• 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字段的值,不能与所要安装的依赖包名字相同。

  • 相关阅读:
    函数的声明
    数组遍历的方法
    运算符
    变量命名规则
    js条件判断
    vuex使用
    高盛伦敦分部面试
    野村证券伦敦分部面试
    Linux Performance Monitoring Commands
    Linux server上too many open files问题
  • 原文地址:https://www.cnblogs.com/blank-string/p/9039961.html
Copyright © 2020-2023  润新知