[英]Error: Cannot find module '../../package.json'
So, I've seen other similar issues.所以,我看到了其他类似的问题。 There are a lot, but I can't seem to find a solution for this.
有很多,但我似乎无法找到解决方案。
I've already deleted node_modules folder and package-lock.json file from /{username}, where my package.json file is.我已经从 /{username} 中删除了 node_modules 文件夹和 package-lock.json 文件,我的 package.json 文件在其中。 However, every time I install something globally, it does not update the package.json file, but does install it in /usr/local/lib/node_modules.
但是,每次我在全局范围内安装某些东西时,它都不会更新 package.json 文件,而是将其安装在 /usr/local/lib/node_modules 中。
This happens every time I run ncu.每次我运行 ncu 时都会发生这种情况。
Any ideas?有任何想法吗?
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '../../package.json'
Require stack:
- /usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js:11:40)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js'
]
}
Node.js v17.0.1
I have just experienced the same.我刚刚经历了同样的事情。 I think it's a bug in the latest version of NCU (12.0.1, released 5 hours ago at the time of writing).
我认为这是最新版本的 NCU(12.0.1,在撰写本文时 5 小时前发布)中的一个错误。
If I run如果我跑
npm install npm-check-updates@12.0.0 -g
then ncu runs fine.然后 ncu 运行良好。
If I run如果我跑
npm install npm-check-updates@12.0.1 -g
then it barfs with this error.然后它会出现这个错误。
I just checked the Github page and found that the issue has already been raised as https://github.com/raineorshine/npm-check-updates/issues/990 .我刚刚检查了 Github 页面,发现该问题已被提出为https://github.com/raineorshine/npm-check-updates/issues/990 。
So I guess, follow that issue for any other workarounds and the eventual fix.所以我想,对于任何其他解决方法和最终修复,请遵循该问题。
I solved this to removing the node_modules folder, package-lock.json file and executing:我解决了这个问题,删除了node_modules文件夹package-lock.json文件并执行:
npm install
I've been scratching my head over this for an hour and the answer by @Alberto Manuel helped me find the solution.我已经为这个问题挠了一个小时,@Alberto Manuel 的回答帮助我找到了解决方案。 I, too, cleared the
node_modules
, package-lock.json
and tried npm install
but that didn't work.我也清除了
node_modules
, package-lock.json
并尝试npm install
,但没有奏效。
Then I did npm install --legacy-peer-deps
after clearing both the node_modules
, package-lock.json
.然后我在清除
node_modules
和package-lock.json
之后安装了npm install --legacy-peer-deps
。 That finally fixed my issue.这终于解决了我的问题。
Looks like npm install
was overriding the legacy versions of dependencies with higher versions or skipping them altogether.看起来
npm install
正在用更高版本覆盖旧版本的依赖项或完全跳过它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.