Docker:找不到React项目的文件

dw1jzc5e  于 12个月前  发布在  Docker
关注(0)|答案(2)|浏览(102)

我正在Docker中设置一个React项目。该项目在我的本地环境中运行良好,但当我尝试使用Docker构建它时,我遇到了一些构建问题

Step 7/7 : RUN npm run build
 ---> Running in 31be0cd260c7

> [email protected] build /app
> react-scripts build

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

./src/Pages/Steps.js
Cannot find file '../Components/Steppers' in './src/Pages'.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1

字符串
以下是我的档案:

Dockerfile

FROM node:alpine

WORKDIR /app

ENV PATH /app/node_modules/.bin:$PATH

COPY package.json /app/package.json
RUN npm install

COPY . /app

RUN npm run build

Package.json

{
  "name": "myproject",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.9.5",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.45",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.1",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "node-sass": "^4.13.1",
    "prop-types": "^15.7.2",
    "query-string": "^6.11.1",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}


当我尝试使用此命令构建它时:

docker build -t myproject:latest .


我在大楼里。任何形式的帮助都将不胜感激。

hec6srdp

hec6srdp1#

容器缺少以下组件之一:
./src/Pages/Steps.js无法在“./src/Pages”中找到文件“../Components/Steppers "。
通过登录容器来仔细检查Steps.js文件是否在容器中。

mspsb9vt

mspsb9vt2#

这个问题是一个区分大小写的问题。我在文件名的大小写上有不一致的地方。我对它们使用了不正确的大写。
我把index.js引用为Index.js,并且错误地引用了大写的其他文件,而不是使用它们的实际情况。
我修复了它们,并正确地引用了它们,构建成功运行。
非常感谢Johnson Bayo Adekunle的帮助。

相关问题