node.js - 为 React App 构建的 Docker 在 Gitlab CI runner 中失败

标签 node.js docker npm gitlab-ci create-react-app

我一直在尝试创建一个 React 应用 Gitlab CI 但它在 RUN npm run build 上一直失败(尝试过 RUN CI=true npm run build 也是)在尝试创建 docker 文件时。

这是我的 Dockerfile

FROM node:8.11.1

# Create app directory
WORKDIR /app/

# Install app dependencies
RUN npm -g install serve

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json /app/

RUN npm install

# Bundle app source
COPY . /app/

RUN ls /app/

#Build react/vue/angular bundle static files
RUN npm run build

EXPOSE 5000
# serve build folder on port 5000
CMD ["serve", "-s", "build", "-p", "5000"]

RUN npm run build 步失败,出现以下错误:

Step 8/10 : RUN npm run build
 ---> Running in d4b3bc5de229

> payed-fe@0.1.0 build /app
> react-scripts build

Creating an optimized production build...
Failed to compile.

./src/index.js
Cannot find file './app' in './src'.


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! payed-fe@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the payed-fe@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!     /root/.npm/_logs/2018-12-20T15_52_14_979Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1
ERROR: Job failed: exit code 1

然而,在我的本地机器上,一切都很顺利(npm start、npm run build,甚至在我的本地构建中成功构建相同的 Dockerfile)。 提前致谢!

--- 编辑 1 --- 是的 ls 在我的本地系统和 CI 上给出相同的输出。 ./src/index.js 只是我的入口文件。以下是内容:

import React from "react";
import ReactDOM from "react-dom";
import App from "./app";
import * as serviceWorker from "./serviceWorker";

ReactDOM.render(<App />, document.getElementById("root"));
serviceWorker.unregister();

是的,路径完全正确,因为它在我的本地机器上成功运行。

--- 编辑 2 ---

在我将工作目录更改为 /payed 之后 /root/.npm/_logs/*.log 的输出 - 仍然没有成功!

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@5.6.0
3 info using node@v8.11.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle payed-fe@0.1.0~prebuild: payed-fe@0.1.0
6 info lifecycle payed-fe@0.1.0~build: payed-fe@0.1.0
7 verbose lifecycle payed-fe@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle payed-fe@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/payed/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle payed-fe@0.1.0~build: CWD: /payed
10 silly lifecycle payed-fe@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle payed-fe@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle payed-fe@0.1.0~build: Failed to exec build script
13 verbose stack Error: payed-fe@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:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
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 emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid payed-fe@0.1.0
15 verbose cwd /payed
16 verbose Linux 4.14.48-coreos-r2
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v8.11.1
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error payed-fe@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the payed-fe@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 ]

最佳答案

尝试 CI=false

CI=true 是默认...

关于node.js - 为 React App 构建的 Docker 在 Gitlab CI runner 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53872196/

相关文章:

javascript - 鼠标选择时突出显示 Pdf 文件中的文本

docker - Go 应用程序在使用 docker-compose 运行时失败并退出,但使用 docker run 命令运行良好

Firebase 在 M1 Mac 上损坏

node.js - 如何打开需要 Node.js 的 Web 应用程序

javascript - 如何像 Visual Studio 项目一样开发/构建 Javascript monorepo 项目?

javascript - 在运行时添加用户密码

node.js - 为什么google appengine部署需要几分钟才能更新服务

node.js - 如何正则表达式将使用 "++++"、 "+++"作为组分隔符的文本输入文件转换为 CSV 或 JSON

Docker 卷文件不可写,以 root 身份写入

macos - OSX X11 错误无法打开显示