Unable to complete package installation npm ERR! Refusing to install package with name “moment“ under a package also called “moment“

Node.js resolves name conflict errors during installation

The installation of the package cannot be completed in node.js, and an error is reported: npm ERR! code ENOSELF npm ERR! Refusing to install package with name “moment” under a package npm ERR! also called “moment”.

The steps I started with:

  1. Created a folder called "moment"

  2. Open the terminal in the "moment" folder of the directory where the command is executed, and enter the npm init -y command in the terminal to quickly create the package.json package management configuration fileInitialize project

  3. I want to download and install a moment package, which will be used to complete subsequent formatting time operations in the futureAbnormal error

*存在 **npm ERR! Refusing to install package with name “moment” under a package also called “moment”. *报错 ;

Reasons for download failure:

During initialization, the project name "moment" (that is, the folder name) created by default is the same as the package name "moment" I want to install, and there is a conflict, resulting in the failure to complete the normal installation
The value of the name field in package.json conflicts with the name of the package to be installed
naming conflict

Solution

  • _Modify the value of the name field in package.json_The
    specific modification method is as follows: inputnpm initcommand to modify the corresponding field value
    after modification

After the modification, the normal installation operation can be completed

finish installation

Guess you like

Origin blog.csdn.net/weixin_42146585/article/details/112487407