typescriptnext.jsbabeljseslint

Type error: Cannot find type definition file for '@babel'


I am writing a next project with following package.json.

{
  "name": "dapp-boilerplate",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
    "format": "prettier --write . --ignore-path .gitignore ./next-env.d.ts",
    "typechain": "typechain --target ethers-v5 --out-dir ./contracts/types './contracts/*.json'"
  },
  "dependencies": {
    "@types/": "metamask/providers",
    "@types/eslint": "^8.4.8",
    "next": "^12.3.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@next/eslint-plugin-next": "^13.0.0",
    "@typechain/ethers-v5": "^10.1.0",
    "@types/node": "^18.11.5",
    "@types/react": "^18.0.22",
    "@typescript-eslint/eslint-plugin": "^5.41.0",
    "@typescript-eslint/parser": "^5.41.0",
    "eslint": "^8.26.0",
    "eslint-config-next": "^13.0.0",
    "eslint-config-prettier": "^8.5.0",
    "ethers": "^5.0.31",
    "prettier": "2.7.1",
    "typechain": "^8.1.0",
    "typescript": "^4.1.3"
  }
}

I have problem with yarn build like this. I thought this was due to eslint but it wasn't the correct reason. Anybody have solution for this?

yarn run v1.22.19
$ next build
info  - Linting and checking validity of types .Failed to compile.

Type error: Cannot find type definition file for '@babel'.
  The file is in the program because:
    Entry point for implicit type library '@babel'

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I tried to deploy to netlify and got unexpected error, So I run yarn build then got upon error.


Solution

  • install the type definition file for babel like this:

     npm i --save-dev @types/babel