我试图运行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

其他回答

尝试移除包锁。Json和node_modules文件夹:

rm package-lock.json
rm -r node_modules
npm uninstall

npm cache clean --force

我试过这两种方法,但都不奏效。之后,我删除了node_modules目录并再次运行npm install,它仍然不起作用。最后,我删除了package-lock。Json,并创建了一个新的包锁。Json文件使用

npm install

我有这个问题,这是由于升级我的git可执行文件。我回滚到Git-2.21.0.rc1.windows。1-64位,并将其添加到我的环境路径,它修复了我的问题。

我尝试了所有方法在我的Mac上解决这个问题。我认为这个问题开始于我已经从Node.js下载了npm,然后在跟随Team Treehouse视频的同时用Homebrew重新安装它。

以下是我的尝试:

从https://docs.npmjs.com/misc/removing-npm

sudo npm uninstall npm -g
sudo make uninstall
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

如何完全卸载Node.js,重新安装(Mac OS X)

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

以下是行之有效的方法:

最后,唯一对我有用的是从GitHub克隆了npm-重装回购,这完全删除了我Mac上与npm相关的所有东西。

https://github.com/brock/node-reinstall

然后我必须从node .js重新安装node和npm。

我也有同样的问题。我尝试过以前的解决方案,但对我来说,解决方案要简单得多。我只需要删除目录中的空格,然后再次运行npm I

感谢:https://github.com/nodejs/node-gyp/issues/809#issuecomment-155019383指出这一点。