【发布时间】:2020-05-28 20:48:27
【问题描述】:
我正在将我的 React、Node 应用程序部署到 openshift 容器平台上。
我在后端同时运行命令。后端运行完美,没有任何问题。前端导致问题。
我正在同时运行这些命令,这些命令位于 package.json 后端文件夹中
"start": "node index.js",
"backend": "nodemon index.js",
"frontend": " npm run start --prefix ../frontend",
"frontendBuilt": "npm run built --prefix ../frontend",
"dev": "concurrently \"npm run backend\" \"npm run frontendBuilt\" ",
我试过以下都没有工作
"frontend": " npm start --prefix /frontend",
"frontendBuilt": "npm built --prefix /frontend",
"frontend": " npm start --prefix ../frontend",
"frontendBuilt": "npm built --prefix ../frontend",
以下是日志文本
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'dev' ]
2 info using npm@6.13.7
3 info using node@v12.2.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle changemaker@1.0.0~predev: changemaker@1.0.0
6 info lifecycle changemaker@1.0.0~dev: changemaker@1.0.0
7 verbose lifecycle changemaker@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle changemaker@1.0.0~dev: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/backend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle changemaker@1.0.0~dev: CWD: /backend
10 silly lifecycle changemaker@1.0.0~dev: Args: [ '-c', 'concurrently "npm run backend" "npm run frontend" ' ]
11 silly lifecycle changemaker@1.0.0~dev: Returned: code: 1 signal: null
12 info lifecycle changemaker@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: changemaker@1.0.0 dev: `concurrently "npm run backend" "npm run frontend" `
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:196: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:196:13)
13 verbose stack at maybeClose (internal/child_process.js:1011:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:268:5)
14 verbose pkgid changemaker@1.0.0
15 verbose cwd /backend
16 verbose Linux 4.18.0-147.3.1.el8_1.x86_64
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
18 verbose node v12.2.0
19 verbose npm v6.13.7
20 error code ELIFECYCLE
21 error errno 1
22 error changemaker@1.0.0 dev: `concurrently "npm run backend" "npm run frontend" `
22 error Exit status 1
23 error Failed at the changemaker@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Starting the development server...
[1]
[1] 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.
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! frontend@0.1.0 start: `react-scripts start`
[1] npm ERR! Exit status 1
[1] npm ERR!
[1] npm ERR! Failed at the frontend@0.1.0 start script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR! /root/.npm/_logs/2020-02-13T07_34_21_726Z-debug.log
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
npm ERR! changemaker@1.0.0 frontend: ` npm start --prefix ../frontend`
[1] npm ERR! Exit status 1
[1] npm ERR!
[1] npm ERR! Failed at the changemaker@1.0.0 frontend script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR! /root/.npm/_logs/2020-02-13T07_34_21_744Z-debug.log
[1] npm run frontend exited with code 1
如果我在 openshift 容器后端文件夹中运行 npm run dev 可以完美运行,没有任何问题
谁能告诉我哪里出错了?
【问题讨论】:
-
react-scripts start 命令是一个 dev 服务器,你不应该在生产环境中运行它。构建前端并让后端为其提供服务(就像我在这里所做的那样:github.com/textbook/starter-kit)或将静态资产部署到单独的(例如 Nginx)容器(可能需要更复杂的网络和配置)。
-
@jonrsharpe 请帮帮我,我是新手,我不知道应该使用“build”:“react-scripts build”,可以吗?该命令在后端同时运行,“要么让后端服务它” - 我理解正确吗?
-
这将创建您需要以某种方式提供服务的文件,是的。
-
@jonrsharpe“以某种方式服务”实际上我不想要某种方式,但这是我正在遵循的好/最好的方式(因为我不知道)还是有很多我不知道的好意识到实现
标签: openshift package.json react-scripts