typescript - 类型错误 : Cannot find type definition file for '@babel'

标签 typescript next.js babeljs eslint

我正在使用以下 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"
  }
}

我遇到这样的yarn build问题。 我认为这是由于 eslint 造成的,但这不是正确的原因。 有人有解决办法吗?

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.

我尝试部署到 netlify 并遇到意外错误,因此我运行 yarn build 然后出现错误。

最佳答案

像这样安装 babel 的类型定义文件:

 npm i --save-dev @types/babel

关于typescript - 类型错误 : Cannot find type definition file for '@babel' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74203139/

相关文章:

Angular 2(或 4)对象序列化

reactjs - 找不到@typescript-eslint/no-unused-expressions'

reactjs - 期望 SWR 库返回缓存数据但没有发生

webpack - Polymer 3 + Webpack -> 没有 'new' 就无法调用 PolymerElement

javascript - 使用 async/await/Promises 在 JavaScript/TypeScript 中实现事件同步原语

javascript - 如何在 typescript 中返回空值?

typescript - 类型错误 : Property 'currentTime' does not exist on type 'EventTarget & HTMLInputElement'

javascript - JSX 在纯 JavaScript 文件中工作,如何?

node.js - 我无法在我的代码中使用 ecma6 导入,出现错误 "unexpected token import "

javascript - 对象字面量中的 "SyntaxError: Unexpected token ..."