@parcel/resolver-default 上的 dockerfile 包裹构建失败:无法加载文件

Parcel build failing with dockerfile on @parcel/resolver-default: Cannot load file

首先是我的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": {    
    [...]
  }
}

docker文件:

# 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;"]

最后是 .docker忽略 :

node_modules
dist
.parcel-cache
.env.local
.gitignore
README.md

使用

在本地构建带有 parcel 的 React 应用程序时

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'导入{工具提示};

加上它在本地工作,那么为什么使用 docker build 会失败?欢迎任何建议和帮助。

在您的最后一个日志中,最后 4 行建议您导入 '../common/Tooltip' 而不是导入 '../common/ToolTip'。其中“tip”有小写字母t.

如果将导入语句更改为带有小写字母 t 的语句并尝试在 Docker 中构建它会发生什么情况?