Refusing to install package with name “XXXX”


我的執行步驟

我創建了一個名叫express的文件夾,想在這個工程中學習express

進入該文件夾,執行npm init來初始化package.json文件,一直回車。

我們會發現當前文件夾多了一個 package.json 文件。

然后安裝express包並保存在package.json的依賴中


npm install express --save

出現錯誤:


10:04:53 @~/code/express$ npm install express --save
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "express" under a package
npm ERR! also called "express". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

問題原因

可以確定我平常使用npm 安裝依賴包的時候,是沒有問題的。

我又看了一下package.json文件,發現我在初始化的時候name字段為express。懷疑是這個問題。

然后我將name字段的值修改為express-test

然后重新執行


npm install express --save

成功后出現:

然后我們再看一下package.json文件:

發現多了一個dependencies字段,里面保存了express的名稱及版本

然后在文件夾內輸入ls,多了個node_modules文件夾

總結

npm install xxxx --save命令會將安裝包的名字及版本保存在package.json文件中

package.json文件中的name字段的值,不能與所要安裝的依賴包名字相同。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM