【node】- npm install时报错:npm WARN enoent ENOENT: no such file or directory

时间:2022-12-10 20:55:36

npm install -g koa 时报错如下所示:

npm WARN enoent ENOENT: no such file or directory

项目目录中没有package.json。

解决方法:

在cmd命令行中输入:

npm config set registry https://registry.npm.taobao.org

npm config set disturl https://npm.taobao.org/dist

再输入npm install -g koa,出现如下图所示:-g表示安装在全局

【node】- npm install时报错:npm WARN enoent ENOENT: no such file or directory

但我在项目中执行npm install koa时,然而又报了相同错!

经过查找资料,找到突破口:可以使用 npm init -f命令生成package.json,package.json中缺少的字段可以参照模板

package.json进行填充,package.json中的字段的值可以为"",依赖项的字段,在安装时通过npm install koa -save

就会自动填充到文件中。

【node】- npm install时报错:npm WARN enoent ENOENT: no such file or directory

生成package.json在执行npm install koa 时出现如下图所示:

【node】- npm install时报错:npm WARN enoent ENOENT: no such file or directory

显示缺少description描述和repository字段

根据模板package.json修改为如下:添加description中的值以及repository字段

{
  "name": "WeiXinNode",
  "version": "1.0.0",
  "description": "23411",
  "main": "index.js",
  "dependencies": {
    "koa": "^2.1.0",
    "sha1": "^1.1.1"  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "repository": {
    "type": "",
    "url": ""  }
}
再执行npm install koa