我试图运行npm install,这是控制台的输出:

npm ERR! Linux 4.8.0-27-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8

npm ERR! Maximum call stack size exceeded
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

这是npm-debug.log的内容:

113791 verbose stack RangeError: Maximum call stack size exceeded
113791 verbose stack     at Object.color (/usr/lib/node_modules/npm/node_modules/npmlog/node_modules/console-control-strings/index.js:115:32)
113791 verbose stack     at EventEmitter.log._format (/usr/lib/node_modules/npm/node_modules/npmlog/log.js:252:51)
113791 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npmlog/log.js:138:24)
113791 verbose stack     at emitThree (events.js:116:13)
113791 verbose stack     at emit (events.js:194:7)
113791 verbose stack     at .<anonymous> (/usr/lib/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-group.js:23:18)
113791 verbose stack     at emitThree (events.js:116:13)
113791 verbose stack     at emit (events.js:194:7)
113791 verbose stack     at .<anonymous> (/usr/lib/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-group.js:23:18)
113791 verbose stack     at emitThree (events.js:116:13)
113791 verbose stack     at emit (events.js:194:7)
113792 verbose cwd /home/giorgi/AdMove/dev/web-advertiser-admove
113793 error Linux 4.8.0-27-generic
113794 error argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
113795 error node v6.9.1
113796 error npm  v3.10.8
113797 error Maximum call stack size exceeded
113798 error If you need help, you may report this error at:
113798 error     <https://github.com/npm/npm/issues>
113799 verbose exit [ 1, true ]

多次删除node_modules,并尝试重新安装。不能理解是什么原因导致了这个,以及如何解决它。


当前回答

在我的案例中,超过最大调用堆栈大小是由另一个错误触发的。日志是这样的:

// ... skipping some deprecation warnings

> core-js@3.6.5 postinstall /root/.nvm/versions/node/v14.10.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-graphql-types-generator/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

sh: 1: node: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/@aws-amplify/cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! Maximum call stack size exceeded

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-09-10T14_10_28_397Z-debug.log

注:sh: 1: node:权限被拒绝,导致我到https://forum.vuejs.org/t/cannot-install-vue-cli-permission-error-in-require-postinstall/82017/7

我必须在安装命令中添加——not - safe-perm,并以root用户运行:

sudo npm install -g --unsafe-perm @aws-amplify/cli

其他回答

我们公司的开发环境使用Artifactory作为我们NPM依赖项的默认注册表,当运行NPM install时,它默认为这个,这不起作用…所以通过NPM install——registry https://registry.npmjs.org手动指定主NPM注册表为我解决了这个问题…

如果这些答案都不适合你,这可能是因为你正在使用的终端不是正确的/你的node_modules被你计算机的另一部分使用。

在我的情况下,我一直在这个错误(最大调用堆栈大小超过)和访问错误事件之间杂耍,当我做了一个sudo npm I。

解决办法是关闭我的IDE(也就是WebStorm),在一个基本终端上运行npm i,就是这样。

我通过以下方法克服了这个问题:

删除npm依赖的所有内容。你可以根据这个线程找到默认的安装位置: https://stackoverflow.com/a/5926706/1850297 在执行npm install命令之前,我建议执行npm cache clean——force

NPM重建肯定会起作用

Metzelder的回答帮助我解决了这个问题。但是如果你运行NPM cache clean命令,它会给你一个消息

从npm@5开始,npm缓存会从损坏问题中自我修复,并且从缓存中提取的数据保证是有效的

所以,从npm5开始,你可以在命令中添加——force标志。

所以命令是:

npm cache clean --force