【问题标题】:Docker yarn build failed with exit code 1Docker 纱线构建失败,退出代码为 1
【发布时间】:2021-09-15 12:00:01
【问题描述】:

我正在尝试使用 docker 构建我的 react 应用程序,当我在本地运行 npm run build 时它成功构建,但是当我使用 docker 构建时,它在构建阶段失败。

我的 docker 文件

FROM node:alpine as builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn
COPY . .
RUN yarn build

# => Run container
FROM nginxinc/nginx-unprivileged:mainline-alpine

# Nginx config
#RUN rm -rf /etc/nginx/conf.d
#COPY conf /etc/nginx

# Static build
COPY --from=builder /app/build /usr/share/nginx/html/
COPY default.conf /etc/nginx/conf.d/

# Default port exposure
EXPOSE 80

# Copy .env file and shell script to container
WORKDIR /usr/share/nginx/html
COPY ./env.sh .
COPY .env .
USER root
# Add bash
RUN apk add --no-cache bash

# Make our shell script executable
RUN chmod +x env.sh

# Start Nginx server
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]

运行命令 docker build -t project 。 下面是输出

 > [builder 7/7] RUN yarn build --no-cache=true:
#14 1.278 yarn run v1.22.5
#14 1.361 $ react-scripts build --no-cache=true
#14 3.409 Creating an optimized production build...
#14 5.746 Failed to compile.
#14 5.746
#14 5.747 ./src/index.js
#14 5.747 TypeError: invalid options argument
#14 5.747     at new Promise (<anonymous>)
#14 5.747     at Generator.throw (<anonymous>)
#14 5.747
#14 5.747
#14 5.778 error Command failed with exit code 1.
#14 5.778 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
executor failed running [/bin/sh -c yarn build --no-cache=true]: exit code: 1

【问题讨论】:

    标签: node.js reactjs docker


    【解决方案1】:

    好的,只是缺少 pacakge-lock.json 文件。问题解决了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多