node.js npm 在每次安装/卸载/ls 时抛出 ENOENT 警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31952747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:14:11  来源:igfitidea点击:

npm throws ENOENT warnings on every install/uninstall/ls

node.jsnpm

提问by Rice

I am trying to do npm install on a Windows 7 shell for some js test development packages directly in a source code repository I cloned locally, in this case karma, chai and mocha.. I consistently get the following errors when trying to install, uninstall other packages.

我正在尝试在 Windows 7 shell 上为一些 js 测试开发包直接在我本地克隆的源代码存储库中执行 npm install,在这种情况下是 karma、chai 和 mocha .. 我在尝试安装、卸载时始终遇到以下错误其他包。

npm WARN ENOENT ENOENT, open '..SourceDirectory\package.json'
npm WARN EPACKAGEJSON ..SourceDirectory\ No description
npm WARN EPACKAGEJSON ..SourceDirectory\ No repository field.
npm WARN EPACKAGEJSON ..SourceDirectory\ No README data
npm WARN EPACKAGEJSON ..SourceDirectory\ No license field.

npm lsalso yields

npm ls也产生

npm ERR! error in ..SourceDirectory\: ENOENT, open '..SourceDirectory\package
.json'

I did pull the beta of the Windows npm upgrade from

我确实从

Windows Upgrade

Windows 升级

because I was running into the file system path length error. I do not have a package.json dependency list located in the warnings' path. Is there a configuration step I missed?

因为我遇到了文件系统路径长度错误。我没有位于警告路径中的 package.json 依赖项列表。有没有我错过的配置步骤?

回答by nick indiessance

Error message might be caused by missing package.jsonfile. Change directory to your project's local directory, as an example (instead, use current working directory of your project):

错误消息可能是由package.json文件丢失引起的。例如,将目录更改为项目的本地目录(而是使用项目的当前工作目录):

cd /var/www/nodeBot

Following string will write package.json:

以下字符串将写入package.json

npm init

Answer menu-driven questions or use --yesto blast past them. Then press enter at the end to write out the file. You might see something like:

回答菜单驱动的问题或用于--yes解决它们。然后在最后按回车键写出文件。您可能会看到类似以下内容:

Wrote to /usr/local/bin/package.json:

{
  "name": "bin",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "twit": "^2.1.1"
},
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

npmis node.js's package manager. package.jsonbecomes npm's configuration or settings file. The twitdependency was a program installed into my project dir. npm install twit

npmisnode.js的包管理器。package.json成为npm的配置或设置文件。该twit依存度安装到我的项目目录的程序。npm install twit



If a package.json file exists in your project's directory, you can use a text editor to fill in empty data fields that can also cause error messages.

如果您的项目目录中存在 package.json 文件,您可以使用文本编辑器来填充也会导致错误消息的空数据字段。

Find the descriptionfield in the package.jsonfile and manually add a description:

descriptionpackage.json文件中找到该字段并手动添加描述:

"description": "This is my latest disruptive technology app.",

In licensefield you can add ISCwhich basically means open source project:

license字段中,您可以添加ISC这基本上意味着开源项目

"license": "ISC"

回答by ARB

I was facing the same problem, so i tried this commands. It works for me

我遇到了同样的问题,所以我尝试了这个命令。这个对我有用

npm install npm@latest -g

npm 安装 npm@latest -g

Hope it will work for you as well

希望它也适用于你

回答by Divya Jalan

I ran the following command and this worked for me!!!

我运行了以下命令,这对我有用!!!

npm cache clean --force

回答by AJ_Temitayo

I had this issue myself, all i did was to remove the package-lock.jsonfile and now it works. Hope this helps someone.

我自己也遇到了这个问题,我所做的就是删除该package-lock.json文件,现在它可以工作了。希望这可以帮助某人。

回答by Nerrve

There could be a problem with your "engines" value in the parent package.json file.

父 package.json 文件中的“engines”值可能有问题。

For example, i had

例如,我有

"engines" : {
    "node": ">=6.10.0",
    "npm": ">=4.3.0"
}

I removed the "npm" key and it just worked (Scratching my head....)

我删除了“npm”键,它就起作用了(挠头……)

回答by saksham

I also faced the same problem but i was doing a silly mistake

我也遇到了同样的问题,但我犯了一个愚蠢的错误

if your npm is installed properly then problem can be confusion between developer to select the current directory to install .js packages. Actually installing anything using npm requires Package.json file in the directory you want to install your package

如果你的 npm 安装正确,那么问题可能是开发人员选择当前目录来安装 .js 包之间的混淆。实际上使用 npm 安装任何东西都需要你要安装包的目录中的 Package.json 文件

eg: npm install abcd

例如: npm install abcd

now if you want to install abcd package via npm make sure you are in the right directory using terminal

现在,如果您想通过 npm 安装 abcd 包,请确保您使用终端位于正确的目录中

eg: my npm directory on my mac is

例如:我的 mac 上的 npm 目录是

/Users/myMac/node_modules/assert-plus/package.json

/Users/myMac/node_modules/assert-plus/package.json

so if make sure you are in directory

所以如果确保你在目录中

/Users/myMac/node_modules/assert-plus

/Users/myMac/node_modules/assert-plus

select this directory via terminal and then write npm install abcd

通过终端选择这个目录,然后写 npm install abcd

回答by Vijay Kalathiya

Had a same problem resolve by

有同样的问题解决了

cd [project folder]
npm cache clean --force
npm install -d
sudo npm update

回答by Leon Johnson

You need to switch into the directory that you're working and then run:

您需要切换到您正在工作的目录,然后运行:

npm -init

After running that, continue to press enter until you get to the end.

运行后,继续按回车键直到结束。