gpt4 book ai didi

javascript - 共享主机上的下一个 JS 构建失败

转载 作者:行者123 更新时间:2023-12-01 17:46:43 24 4
gpt4 key购买 nike

当我在共享托管服务器上运行“npm run build”时,它会抛出错误:spawn ENOMEM它在我的本地主机上运行良好,并且在托管服务器上运行良好几周,直到昨天。

> mysite@1.0.0 build /home/user123/public_html
> next build

Creating an optimized production build ...internal/child_process.js:366
throw errnoException(err, 'spawn');
^

Error: spawn ENOMEM
at ChildProcess.spawn (internal/child_process.js:366:11)
at spawn (child_process.js:551:9)
at Object.fork (child_process.js:113:10)
at ChildProcessWorker.initialize (/home/user123/public_html/node_modules/jest-worker/build/workers/ChildProcessWorker.js:137:44)
at new ChildProcessWorker (/home/user123/public_html/node_modules/jest-worker/build/workers/ChildProcessWorker.js:127:10)
at WorkerPool.createWorker (/home/user123/public_html/node_modules/jest-worker/build/WorkerPool.js:44:12)
at new BaseWorkerPool (/home/user123/public_html/node_modules/jest-worker/build/base/BaseWorkerPool.js:82:27)
at new WorkerPool (/home/user123/public_html/node_modules/jest-worker/build/WorkerPool.js:30:1)
at new JestWorker (/home/user123/public_html/node_modules/jest-worker/build/index.js:131:26)
at TaskRunner.run (/home/user123/public_html/node_modules/next/dist/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js:3:166)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mysite@1.0.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mysite@1.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! /home/user123/.npm/_logs/2019-09-24T19_27_41_300Z-debug.log

这是调试日志

0 info it worked if it ends with ok
1 verbose cli [ '/home/user123/node/bin/node',
1 verbose cli '/home/user123/node/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm@6.11.3
3 info using node@v10.16.3
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle mysite@1.0.0~prebuild: mysite@1.0.0
6 info lifecycle mysite@1.0.0~build: mysite@1.0.0
7 verbose lifecycle mysite@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle mysite@1.0.0~build: PATH: /home/user123/node/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/user123/public_html/node_modules/.bin:/home/user123/node/bin:/home/user123/node/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/cpanel/composer/bin:/opt/puppetlabs/bin:/opt/dell/srvadmin/bin:/usr/local/bin:/usr/X11R6/bin:/home/user123/.local/bin:/home/user123/bin
9 verbose lifecycle mysite@1.0.0~build: CWD: /home/user123/public_html
10 silly lifecycle mysite@1.0.0~build: Args: [ '-c', 'next build' ]
11 silly lifecycle mysite@1.0.0~build: Returned: code: 1 signal: null
12 info lifecycle mysite@1.0.0~build: Failed to exec build script
13 verbose stack Error: mysite@1.0.0 build: `next build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/home/user123/node/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/home/user123/node/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid mysite@1.0.0
15 verbose cwd /home/user123/public_html
16 verbose Linux 2.6.32-954.3.5.lve1.4.66.el6.x86_64
17 verbose argv "/home/user123/node/bin/node" "/home/user123/node/bin/npm" "run" "build"
18 verbose node v10.16.3
19 verbose npm v6.11.3
20 error code ELIFECYCLE
21 error errno 1
22 error mysite@1.0.0 build: `next build`
22 error Exit status 1
23 error Failed at the mysite@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

我正在使用express和next js。这是我的 server.js

const express = require( 'express' );
const next = require( 'next' );

// Import middleware.
const routes = require( './routes' );

// Setup app.
const app = next( { dev: 'production' !== process.env.NODE_ENV } );
const handle = app.getRequestHandler();
const handler = routes.getRequestHandler( app );

app.prepare()
.then( () => {

// Create server.
const server = express();

// Use our handler for requests.
server.use( handler );

// Don't remove. Important for the server to work. Default route.
server.get( '*', ( req, res ) => {
return handle( req, res );
} );

// Get current port.
const port = process.env.PORT || 8080;

// Error check.
server.listen( port, err => {
if ( err ) {
throw err;
}

// Where we starting, yo!
console.log( `> Ready on port ${port}...` );
} );
} );

我研究了交换空间/内存,看起来没问题

             total       used       free     shared    buffers     cached
Mem: 31906 31330 575 21 2982 16900
-/+ buffers/cache: 11447 20459
Swap: 8191 0 8191

我也尝试过 NODE_OPTIONS=--max-old-space-size=2048 npm run build 但仍然不起作用

有人知道出了什么问题吗?

最佳答案

它似乎与 NextJs 版本 9 有关,因为它在构建应用程序时消耗了太多内存。您可以在这里找到有关该问题的讨论:https://github.com/zeit/next.js/issues/7929

版本 8 似乎没有这个问题,所以如果您选择降级,您现在可以这样做。

此外,如果仍然没有帮助,在 next.config.js 中禁用最小化将减少内存使用量:

module.exports = {
webpack: (config, options) => {
config.optimization.minimize = false;
return config
}
}

如果您不想排除最小化,我发现使用版本 8,您可以在本地构建应用程序并将已构建的文件夹移动到共享主机,而无需再次在共享主机上运行“下一个构建”。我无法在版本 9 中做到这一点。

更新:在 NextJs 版本 8.1 上测试

关于javascript - 共享主机上的下一个 JS 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58087173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com