您的nodejs版本v12.14.1与您的打字稿目标esnext之间存在不匹配

发布于 2025-01-24 04:38:55 字数 196 浏览 2 评论 0原文

我正在使用v12.14.1版本,在我的项目中尝试键入NPM运行测试时,我会收到此警告您的nodejs版本v12.14.1与您的打字稿目标esnext之间存在不匹配。使用TS-JEST 运行测试时,这可能会导致一些意外错误

,并且我的所有测试都失败了,请您说出我应该使用什么节点版本,或者我如何修复此警告,通过我的测试

I am using v12.14.1 version, in my project when try to type npm run test, I am getting this warning There is a mismatch between your NodeJs version v12.14.1 and your TypeScript target ESNext. This might lead to some unexpected errors when running tests with ts-jest

and all my test is failed, please can you say what node version should I use, or how can I fix this warning, to pass my tests

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2025-01-31 04:38:55

答案是在此 cheatsheet

您正在运行节点版本12,因此您必须设置“ target”:“ ES2019”
“ lib”:[“ ES2019”]在您的tsconfig.json中。

tsconfig的外观示例:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "noImplicitAny": false,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "./dist",
    "sourceMap": true,
    "strict": true,
    "target": "es2019",
    "lib": [
      "es2019",
      "es2020.bigint",
      "es2020.string",
      "es2020.symbol.wellknown"
    ],
    "typeRoots": ["node_modules/@types"],
    "resolveJsonModule": true
  },
  "compileOnSave": true,
  "include": ["./src/**/*"],
  "exclude": ["node_modules"]
}

The answer is in this cheatsheet.

You are running node version 12, so you must set "target": "es2019"
and "lib": ["ES2019"] in your tsconfig.json.

Example of what your tsconfig can look like:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "noImplicitAny": false,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "./dist",
    "sourceMap": true,
    "strict": true,
    "target": "es2019",
    "lib": [
      "es2019",
      "es2020.bigint",
      "es2020.string",
      "es2020.symbol.wellknown"
    ],
    "typeRoots": ["node_modules/@types"],
    "resolveJsonModule": true
  },
  "compileOnSave": true,
  "include": ["./src/**/*"],
  "exclude": ["node_modules"]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文