create-react-app 构建过程花费的时间太长
create-react-app build process take too long
我们从合作伙伴那里收到了一个前端,用于与我们使用 create-create-app 构建的 API(内置于 node.js)进行交互,在从我们的合作伙伴 [=37= 克隆回购之后],
npm start
命令有效,我可以在本地测试与 API 交互的应用程序,完全没有问题。
同样在我的本地机器上,npm run build
命令运行良好,我能够使用 serve build
命令构建和 运行 应用程序。
将存储库克隆到 Amazon AWS EC2 实例后出现问题,我能够克隆存储库但是在 运行 宁 npm install
之后,当 运行 宁 npm run build
该进程只是永远停留在以下消息中:
sudo npm run build
> sensores@0.1.0 build /var/www/smartdots-frontend
> react-scripts build
Creating an optimized production build...
大约 20 分钟后,进程一直挂起,最后这是最后一条消息:
> sensores@0.1.0 build /var/www/smartdots-frontend
> react-scripts build
Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sensores@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sensores@0.1.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/ubuntu/.npm/_logs/2019-01-12T21_26_31_254Z-debug.log
最后,这是日志:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.5.0
3 info using node@v11.6.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle sensores@0.1.0~prebuild: sensores@0.1.0
6 info lifecycle sensores@0.1.0~build: sensores@0.1.0
7 verbose lifecycle sensores@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle sensores@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/smartdots-frontend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
9 verbose lifecycle sensores@0.1.0~build: CWD: /var/www/smartdots-frontend
10 silly lifecycle sensores@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle sensores@0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle sensores@0.1.0~build: Failed to exec build script
13 verbose stack Error: sensores@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:188:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:188:13)
13 verbose stack at maybeClose (internal/child_process.js:978:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid sensores@0.1.0
15 verbose cwd /var/www/smartdots-frontend
16 verbose Linux 4.4.0-1069-aws
17 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v11.6.0
19 verbose npm v6.5.0
20 error code ELIFECYCLE
21 error errno 1
22 error sensores@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the sensores@0.1.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 ]
我已经在几台机器上测试了 npm run build
,使用不同的 OS,它总是 运行 很好,对此我真的很绝望,我已经尝试构建应用程序作为 root,更改文件夹权限和所有权,但没有任何效果,在另一台计算机上构建应用程序并在 AWS 机器上提供它也不起作用
node --version
v11.6.0
npm --version
6.5.0
create-react-app --version
2.1.3
package.json:
{
"name": "sensores",
"version": "0.1.0",
"private": true,
"dependencies": {
"antd": "^3.11.3",
"history": "^4.7.2",
"moment": "^2.23.0",
"pm2": "^3.2.8",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-draggable": "^3.1.1",
"react-form": "^3.5.6",
"react-loader-spinner": "^2.3.0",
"react-redux": "^6.0.0",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "^2.1.3",
"reactstrap": "^6.5.0",
"recharts": "^1.4.2",
"redux": "^4.0.1",
"redux-form": "^8.0.4",
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.2",
"redux-thunk": "^2.3.0",
"serve": "^10.1.1",
"styled-components": "^4.1.3",
"url-search-params": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"serve": "json-server --watch ./serverfake.json"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
听起来确实是内存问题,尤其是这一行:
The build failed because the process exited too early. This probably means the system ran out of memory or someone called
kill -9on the process.
.
您可以通过运行终端内的命令top
查看内存使用情况。
我们从合作伙伴那里收到了一个前端,用于与我们使用 create-create-app 构建的 API(内置于 node.js)进行交互,在从我们的合作伙伴 [=37= 克隆回购之后],
npm start
命令有效,我可以在本地测试与 API 交互的应用程序,完全没有问题。
同样在我的本地机器上,npm run build
命令运行良好,我能够使用 serve build
命令构建和 运行 应用程序。
将存储库克隆到 Amazon AWS EC2 实例后出现问题,我能够克隆存储库但是在 运行 宁 npm install
之后,当 运行 宁 npm run build
该进程只是永远停留在以下消息中:
sudo npm run build
> sensores@0.1.0 build /var/www/smartdots-frontend
> react-scripts build
Creating an optimized production build...
大约 20 分钟后,进程一直挂起,最后这是最后一条消息:
> sensores@0.1.0 build /var/www/smartdots-frontend
> react-scripts build
Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sensores@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sensores@0.1.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/ubuntu/.npm/_logs/2019-01-12T21_26_31_254Z-debug.log
最后,这是日志:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.5.0
3 info using node@v11.6.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle sensores@0.1.0~prebuild: sensores@0.1.0
6 info lifecycle sensores@0.1.0~build: sensores@0.1.0
7 verbose lifecycle sensores@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle sensores@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/smartdots-frontend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
9 verbose lifecycle sensores@0.1.0~build: CWD: /var/www/smartdots-frontend
10 silly lifecycle sensores@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle sensores@0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle sensores@0.1.0~build: Failed to exec build script
13 verbose stack Error: sensores@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:188:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:188:13)
13 verbose stack at maybeClose (internal/child_process.js:978:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid sensores@0.1.0
15 verbose cwd /var/www/smartdots-frontend
16 verbose Linux 4.4.0-1069-aws
17 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v11.6.0
19 verbose npm v6.5.0
20 error code ELIFECYCLE
21 error errno 1
22 error sensores@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the sensores@0.1.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 ]
我已经在几台机器上测试了 npm run build
,使用不同的 OS,它总是 运行 很好,对此我真的很绝望,我已经尝试构建应用程序作为 root,更改文件夹权限和所有权,但没有任何效果,在另一台计算机上构建应用程序并在 AWS 机器上提供它也不起作用
node --version
v11.6.0
npm --version
6.5.0
create-react-app --version
2.1.3
package.json:
{
"name": "sensores",
"version": "0.1.0",
"private": true,
"dependencies": {
"antd": "^3.11.3",
"history": "^4.7.2",
"moment": "^2.23.0",
"pm2": "^3.2.8",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-draggable": "^3.1.1",
"react-form": "^3.5.6",
"react-loader-spinner": "^2.3.0",
"react-redux": "^6.0.0",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "^2.1.3",
"reactstrap": "^6.5.0",
"recharts": "^1.4.2",
"redux": "^4.0.1",
"redux-form": "^8.0.4",
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.2",
"redux-thunk": "^2.3.0",
"serve": "^10.1.1",
"styled-components": "^4.1.3",
"url-search-params": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"serve": "json-server --watch ./serverfake.json"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
听起来确实是内存问题,尤其是这一行:
The build failed because the process exited too early. This probably means the system ran out of memory or someone called
kill -9on the process.
.
您可以通过运行终端内的命令top
查看内存使用情况。