空白格丶

  博客园  :: 首页  :: 新随笔  ::  ::  :: 管理

我的执行步骤

我创建了一个名叫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字段的值,不能与所要安装的依赖包名字相同。

posted on 2018-05-15 11:19  空白格丶  阅读(3495)  评论(0编辑  收藏  举报