错误:这可能不是 npm 的问题。上面可能有额外的日志输出

Ind*_*ake 32 deployment build node.js npm angular

在我的项目中,我使用 Angular6 作为前端。现在我要做的是将远程服务器中的项目部署到实际服务器中。我首先使用npm run build -prod命令来构建前端。但是我无法构建我的项目,因为以下错误一次又一次发生,

npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! Trackit-Revamp@6.0.0 build: `ng build --prod --build-optimizer --aot`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the Trackit-Revamp@6.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Indrajith.E\AppData\Roaming\npm-cache\_logs\2019-08-22T08_41_00_271Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我在C:\Users\Indrajith.E\AppData\Roaming\npm-cache\_logs\2019-08-22T08_41_00_271Z-debug.log文件路径中的错误日志包含与上述相同的错误详细信息。

我该如何解决这个问题?

Oma*_*iel 53

Delete your package-lock.json file and node_modules folder. Then do npm cache clean

npm cache clean --force
Run Code Online (Sandbox Code Playgroud)

do npm install

again and run


Ind*_*ake 18

最后,我在不重新安装 npm 的情况下找到了解决此问题的方法,我将其发布,因为将来它会对某人有所帮助,大多数情况下都会发生此错误,因为 javascript 堆内存不足。正如错误本身所说,这不是 npm 的问题。我们唯一要做的就是

代替,

npm  run build -prod
Run Code Online (Sandbox Code Playgroud)

通过以下方式扩展javascript内存,

node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --prod
Run Code Online (Sandbox Code Playgroud)

  • 我们只需在终端上输入这个吗?不适合我。 (2认同)
  • 但在 React 项目中你能做这种事情吗? (2认同)

小智 9

请删除package-lock.json并清除 npm 缓存并npm cache clear --force 删除整个node_modules目录

最后使用npm install/再次安装或更新软件包npm update 您还可以使用以下命令添加任何新软件包npm install <package-name>

这对我来说是固定的。

谢谢,编码愉快。


Dio*_*ros 8

我在Ubuntu 18.04 上。我通过使用以下命令增加inotify max_user_watches解决了这个问题:

回声65536 | 须藤三通 -a /proc/sys/fs/inotify/max_user_watches


小智 6

我是反应新手...我有相同的输出:

Starting the development server...

events.js:196
      throw er; // Unhandled 'error' event
      ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/opt/lampp/htdocs/react-tuto/public'
    at FSWatcher.<computed> (internal/fs/watchers.js:168:26)
    at Object.watch (fs.js:1351:34)
    at createFsWatchInstance (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:38:15)
    at setFsWatchListener (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:81:15)
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:233:14)
    at FSWatcher.NodeFsHandler._handleDir (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:429:19)
    at FSWatcher.<anonymous> (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:477:19)
    at FSWatcher.<anonymous> (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:482:16)
    at FSReqCallback.oncomplete (fs.js:165:5)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/index.js:260:10)
    at createFsWatchInstance (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:40:5)
    at setFsWatchListener (/opt/lampp/htdocs/react-tuto/node_modules/chokidar/lib/nodefs-handler.js:81:15)
    [... lines matching original stack trace ...]
    at FSReqCallback.oncomplete (fs.js:165:5) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/opt/lampp/htdocs/react-tuto/public',
  filename: '/opt/lampp/htdocs/react-tuto/public'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-tuto@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-tuto@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/paulo/.npm/_logs/2019-12-16T16_46_27_856Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我刚刚尝试过:

sudo npm start
Run Code Online (Sandbox Code Playgroud)

它奏效了。


Moh*_*BLI 5

我已经有同样的问题了。我使用npm updatenpm cache clean --force修复它