【发布时间】:2022-01-26 20:48:42
【问题描述】:
首先是我的 package.json(已修整):
{
"name": "polk-auction-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
[...]
},
"scripts": {
"start": "cross-env NODE_ENV=local parcel ./src/index.html -p 3000",
"start:prod": "cross-env NODE_ENV=prod parcel ./src/index.html -p 3000",
"test": "jest",
"build:prod": "cross-env NODE_ENV=prod parcel build ./src/index.html"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"devDependencies": {
[...]
},
"jest": {
[...]
}
}
码头文件:
# Build step
FROM node:14 as build
WORKDIR /app
COPY package*.json ./
RUN yarn install
COPY . ./
RUN yarn build:prod
# Run step
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
最后是 .dockerignore :
node_modules
dist
.parcel-cache
.env.local
.gitignore
README.md
在本地使用包裹构建反应应用时
yarn build:prod
它确实构建正确。
但是当我运行以下命令时:
docker build -t polk-auction-ui .
它在 [build 6/6] 上失败并出现以下错误(已删除警告):
#12 4.440 @parcel/core: Failed to resolve '../common/ToolTip' from
#12 4.440 './src/components/crowdloan/CrowdloanTable.tsx'
#12 4.440
#12 4.440 /app/src/components/crowdloan/CrowdloanTable.tsx:26:11
#12 4.440 25 | <th>Lease Periods</th>
#12 4.440 > 26 | <th>Raised</th>
#12 4.440 > | ^
#12 4.440 27 | <th />
#12 4.440 28 | <th />
#12 4.440
#12 4.441 @parcel/resolver-default: Cannot load file '../common/ToolTip' in
#12 4.441 './src/components/crowdloan'.
#12 4.441 ???? Did you mean '../common/Tooltip'?
#12 4.442 ???? Did you mean '../common/Common'?
这很奇怪,因为 CrowdloanTable.tsx 确实有以下导入: 从'../common/ToolTip'导入{ Tooltip };
加上它在本地工作,那么为什么使用 docker build 会失败?欢迎任何建议和帮助。
【问题讨论】:
标签: reactjs docker dockerfile parceljs