Docker 构建抛出“react-scripts: not found”错误

Ban*_*our 8 docker create-react-app

我正在使用 create-react-app 并想用 Docker 发布我的项目。使用docker build . -t react-docker命令,我收到此错误:

/bin/sh: 1: react-scripts: not found 错误命令失败,退出代码为 127。

我删除package-lock.json并运行npm install,问题还是没有解决!

Dockerfile:

# stage: 1 
FROM node:8 as react-build 
WORKDIR /app 
COPY . ./ 
RUN yarn 
RUN yarn build 
# stage: 2 — the production environment 
FROM nginx:alpine 
COPY — from=react-build /app/build /usr/share/nginx/html 
EXPOSE 80 
CMD [“nginx”, “-g”, “daemon off;”]
Run Code Online (Sandbox Code Playgroud)

rap*_*piz 3

您正在处理卷吗?通过正常安装,docker 应该可以访问您的资源。但我在同事的机器上看到存在一些奇怪的权限问题。所以 docker 在尝试时无法写入yarn install。所以没有node_modules创建(正如您在讨论中所描述的那样)。因此没有react-scripts

解决方案:授予其他人访问您要安装的位置的权限。或者不使用卷。