node.js 使用 Node 8.9.4 LTS 安装 Sails.js 依赖项时的 NPM“ENOENT:没有此类文件或目录错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48384811/
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 18:39:43  来源:igfitidea点击:

NPM "ENOENT: no such file or directory error" when installing Sails.js dependencies with Node 8.9.4 LTS

node.jsnpmsails.js

提问by Nag

I recently upgraded my computer and with it, to the latest LTS version of Node and NPM:

我最近升级了我的计算机并使用它升级到最新的 LTS 版本的 Node 和 NPM:

  • Node.js 8.9.4
  • NPM 5.6.0
  • Node.js 8.9.4
  • 新产品管理 5.6.0

I have a Sails.js 0.12.14 application for which I'm trying to install NPM dependencies with npm installbut when I do that, I get the following errors:

我有一个 Sails.js 0.12.14 应用程序,我正在尝试为其安装 NPM 依赖项,npm install但是当我这样做时,我收到以下错误:

?  web-service git:(feature/auth) ? npm install
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/package.json'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/README.md'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/LICENSE'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/index.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/CHANGELOG.md'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/camelCase.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/uniqueId.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/bindKey.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/unnest.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/bindAll.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/unset.js'
// a bunch of similar Lodash errors removed from here
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/T.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/zipWith.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/lastIndexOfFrom.js'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/oauth-sign):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/oauth-sign-b13c86db'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/mkdirp):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/mkdirp-c94c8047'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/mkdirp/node_modules/minimist):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/minimist-ba966a6e'

npm ERR! path /Users/Nag/Code/project/web-service/node_modules/.staging/sails-02afd14e/node_modules/@sailshq/body-parser
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/Users/Nag/Code/project/web-service/node_modules/.staging/sails-02afd14e/node_modules/@sailshq/body-parser' -> '/Users/Nag/Code/project/web-service/node_modules/.staging/@sailshq/body-parser-6d1e8405'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Nag/.npm/_logs/2018-01-22T14_40_13_889Z-debug.log

I can't seem to figure out what's going on and can't find suitable answers anywhere else online. I even ran npm cache clean --force, rm -rf node_modulesand retried with similar errors. It seemed to work fine when I was on Node ~6 but after upgrading to Node 8.9.4 and NPM 5.6.0, it just won't install my dependencies. How can I resolve this?

我似乎无法弄清楚发生了什么,也无法在网上其他任何地方找到合适的答案。我什至跑了npm cache clean --forcerm -rf node_modules并重试了类似的错误。当我在 Node ~6 上时,它似乎工作正常,但在升级到 Node 8.9.4 和 NPM 5.6.0 后,它不会安装我的依赖项。我该如何解决这个问题?

回答by tantalum

Try deleting the package-lock.jsonfile.

尝试删除package-lock.json文件。

回答by coturiv

No permission, no internet issue, it's just a general issue of npm. I solved the problem with yarn.

没有许可,没有互联网问题,这只是npm. 我用yarn解决了这个问题。

yarn install

Or you can use no-optionalflag.

或者你可以使用no-optional标志。

npm install --no-optional

回答by Neha Sharma

Just delete package-lock.jsonfile and then install package(s) you want. All will work.

只需删除package-lock.json文件,然后安装所需的软件包即可。一切都会奏效。

回答by jspru

Deleting and regenerating 'package-lock.json' usually solves this issue however that's inherently risky because you will likely be upgrading multiple packages at a time.

删除并重新生成“package-lock.json”通常可以解决这个问题,但这本身就有风险,因为您可能一次升级多个包。

In my case it turned out that there was one specific package version that package-lock.json was referencing, that was 5 levels deep in the dependency. That version no longer existed at the npm registry so it caused the install to break. I had to find which package was pulling in this dependency and upgrade that one to resolve the issue.

在我的例子中,结果是 package-lock.json 引用了一个特定的包版本,在依赖项中有 5 个级别。该版本不再存在于 npm 注册表中,因此导致安装中断。我必须找到哪个包引入了这个依赖项并升级那个包来解决这个问题。

回答by StriplingWarrior

For me, it turned out these errors were hiding the real underlying problem, which was that my credentials for a third-party npm repository (azure devops) had expired. I had to re-run vsts-npm-auth -config .npmrcto update the token in my .npmrcfile.

对我来说,事实证明这些错误隐藏了真正的潜在问题,即我的第三方 npm 存储库 (azure devops) 的凭据已过期。我不得不重新运行vsts-npm-auth -config .npmrc以更新我.npmrc文件中的令牌。

回答by Severun

I was struggling with this for awhile, and it seems be be related to the following.

我为此苦苦挣扎了一段时间,似乎与以下内容有关。

Let's say you have 3 modules, A, B and C

假设您有 3 个模块,A、B 和 C

Module A includes B and C directly Module B also includes module C, in it's package.json dependencies.

模块 A 直接包含 B 和 C 模块 B 还包含模块 C,在它的 package.json 依赖项中。

If your package.json dependencies in module A look like the following:

如果模块 A 中的 package.json 依赖项如下所示:

"dependencies": {
     "C": "^1.0.0",
     "B": "^1.1.0"
}

You will get the above error you mentioned, ENOENT, blah, blah in .staging

您将在 .staging 中收到上述错误,ENOENT,等等,等等

If on the other hand you include the module with the nested include first like:

另一方面,如果您首先包含具有嵌套包含的模块,例如:

"dependencies": {
     "B": "^1.1.0",
     "C": "^1.0.0"
}

The error goes away. This seems like a bug in npm with nested dependencies, and the error messages and logs were not very descriptive. Check your dependency tree and see if you have the described case, if so, that is your issue.

错误消失了。这似乎是 npm 中带有嵌套依赖项的错误,并且错误消息和日志没有很好的描述性。检查你的依赖树,看看你是否有描述的情况,如果有,那就是你的问题。

回答by ?eljko ?evi?

Beside removing package-lock.jsonI had to remove node_modulesso package-lock.jsoncould be generated in the right way

除了删除package-lock.json我必须删除node_modules所以package-lock.json可以以正确的方式生成

rm -rf node_modules
rm package-lock.json
npm i