1

I have my hardhat project that builds and run fine using yarn. But when I try to execute "yarn build" from a Dockerfile during the image build process I have the following error:

=> ERROR [7/8] RUN yarn build 17.0s

[7/8] RUN yarn build:
#11 0.383 yarn run v1.22.19
#11 0.420 $ npx tsc -p tsconfig.json
#11 16.59 error TS2688: Cannot find type definition file for '@nomiclabs/hardhat-ethers'.
#11 16.59 The file is in the program because:
#11 16.59 Entry point of type library '@nomiclabs/hardhat-ethers' specified in compilerOptions #11 16.59 error TS2688: Cannot find type definition file for '@nomiclabs/hardhat-waffle'. #11 16.59 The file is in the program because: #11 16.59 Entry point of type library '@nomiclabs/hardhat-waffle' specified in compilerOptions

This is my Dockerfile

FROM node:lts-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "tsconfig.*", "hardhat.*", "./"
RUN apk add --no-cache git
RUN yarn install --production --silent && mv node_modules ../
COPY . .
RUN yarn build
EXPOSE 3000
RUN chown -R node /usr/src/app
USER node
CMD ["npm", "run", "track:inventory"]

This is the content of my package.json

{
  "name": "bot-ts",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "npx tsc -p tsconfig.json",
    "start": "node ./dist/index.js",
    "dev": "npx ts-node src/index.ts",
    "test": "npx hardhat test",
    "track-inventory": "npx ts-node src/inventory/track.ts",
    "clear": "rm -r ./dist"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.2.2",
    "@nomiclabs/hardhat-etherscan": "^3.1.7",
    "@nomiclabs/hardhat-waffle": "^2.0.5",
    "@typechain/ethers-v5": "10.2.0",
    "@typechain/hardhat": "^6.1.5",
    "@types/chai": "^4.3.4",
    "@types/mocha": "^10.0.1",
    "@types/node": "^18.15.10",
    "@types/sinon": "^10.0.13",
    "@types/ws": "^8.5.4",
    "chai": "^4.3.7",
    "ethereum-waffle": "^3.4.4",
    "mocha": "^10.2.0",
    "prettier": "^2.8.7",
    "sinon": "^15.0.3",
    "ts-node": "^10.9.1",
    "typescript": "^5.0.2"
  },
  "dependencies": {
    "@types/express": "^4.17.17",
    "@types/pg": "^8.6.6",
    "@types/sinon-chai": "^3.2.9",
    "bignumber.js": "^9.1.1",
    "ccxt": "3.0.54",
    "dotenv": "^16.0.3",
    "ethereum-multicall": "^2.16.1",
    "ethers": "^5.7.2",
    "express": "^4.18.2",
    "graphql": "^16.6.0",
    "graphql-request": "^5.2.0",
    "hardhat": "^2.13.0",
    "pg": "^8.10.0",
    "prom-client": "^14.2.0",
    "rotating-file-stream": "^3.0.4",
    "tslog": "^4.8.2"
  }
}

And finally here it is my tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es2018",
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "resolveJsonModule": true,
    "typeRoots": ["./typechain", "./node_modules/@types"],
    "types": ["@nomiclabs/hardhat-ethers", "@nomiclabs/hardhat-waffle"],
    "noUnusedLocals": true,
    "strict": true
  },
  "include": ["src/**/*.ts", "test/**/*.ts", "src/**/*.json"],
  "exclude": ["node_modules"]
}

Any help on how to make my docker build command succesfuly create the image?

1 Answer 1

0

The type definition files for @nomiclabs/hardhat-ethers and @nomiclabs/hardhat-waffle are missing during the Docker build.

Just remove the --production flag from the yarn install

FROM node:lts-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "tsconfig.*", "hardhat.*", "./"]
RUN apk add --no-cache git
RUN yarn install --silent && mv node_modules ../
COPY . .
RUN yarn build
EXPOSE 3000
RUN chown -R node /usr/src/app
USER node
CMD ["npm", "run", "track:inventory"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.