簡體   English   中英

docker 容器構建失敗

[英]docker container build failing

我正在嘗試將我的服務轉移到 Docker 容器中。 構建項目在本地運行良好,但是當我嘗試將其構建為 docker 構建的一部分時,出現以下錯誤:

node_modules/jest-extended/types/index.d.ts(135,39): error TS2694: Namespace 'jest' has no exported member 'Mock'.

請找到我的dockerfile:

FROM node:12
COPY package.json /opt/service/
WORKDIR /opt/service/
RUN npm install
COPY . .
RUN npm run build
...

package.json相關部分

"scripts": {
  "build": "rm -rf lib && graphql-codegen && tsc -p tsconfig.json && copyfiles -u 1 ./src/**/*.graphql lib && copyfiles -u 1 ./src/**/*.proto lib"
},
"devDependencies": {
  "@graphql-codegen/cli": "1.17.8",
  "@graphql-codegen/typescript": "1.17.8",
  "@graphql-codegen/typescript-resolvers": "^1.18.1",
  "@types/jest": "^27.0.2",
  "@types/node": "^16.10.2",
  "copyfiles": "^2.3.0",
  "graphql": "14.7.0",
  "jest": "27.2.4",
  "jest-cli": "27.2.4",
  "jest-extended": "^0.11.5",
  "nodemon": "^2.0.4",
  "ts-jest": "^27.0.5",
  "ts-node": "^10.2.1",
  "typescript": "^3.9.7"
},

tsconfig.json

"compilerOptions": {
  "target": "es2016",
  "module": "commonjs",
  "lib": ["es2019", "dom"],
  "strict": true,
  "noImplicitAny": true,
  "noUnusedLocals": true,
  "noUnusedParameters": true,
  "noImplicitReturns": true,
  "typeRoots": ["node_modules/@types"],
  "esModuleInterop": true,
  "resolveJsonModule": true,
  "outDir": "lib",
  "rootDir": "src",
  "resolveJsonModule": true,
  "allowJs": true
},
"ts-node": {
  "transpileOnly": true,
  "files": true
},
"include": ["**/*"],
"exclude": ["node_modules", "lib", "jest.*.ts", "jest.*.js", "**/generated/*"]

編輯:

在我的 compilerOptions 中添加"skipLibCheck": true修復了Namespace 'jest' has no exported member 'Mock' error.

盡管我之前沒有提到我希望通過修復第一個錯誤得到解決,但我仍然遇到錯誤。

我仍然從 *.test.ts 文件中得到的錯誤是:

error TS2708: Cannot use namespace 'jest' as a value.
error TS2304: Cannot find name 'expect'.
error TS2304: Cannot find name 'beforeAll'.
error TS2582: Cannot find name 'test'.

我有一個想法也許可以解決您的問題,因為我有一個類似的問題是由於版本沖突引起的。 您能否嘗試將您的 package-lock.json 文件也復制到您的 docker 圖像中?

...
COPY package.json /opt/service/
COPY package-lock.json /opt/service/
...

結果證明這是 tsconfig.json 和我的文件夾結構的問題。 我在這個項目中有多個服務和包。 在根文件夾(每個服務的兩個文件夾)中,我有一個 tsconfig.json 文件,其他服務和包正在擴展。 因為我只從根而不是 node_modules 復制 tsconfig.json 文件,並且根 tsconfig.json 文件聲明"typeRoots": ["node_modules/@types"] ,服務期望在../../node_modules

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM