Pro*_*ard 9 javascript config node.js typescript jestjs
我正在尝试用笑话设置一个打字稿项目。然而,打字稿似乎没有从 中获取笑话类型@types/jest
,这突出显示了我的关键字,给了我以下错误:
Cannot find name 'test'. Do you need to install type definitions for a test runner? Try 'npm i @types/jest' or 'npm i @types/mocha'. ts(2582)
笔记:
{
"compilerOptions": {
"types": ["jest", "node"]
},
"types": ["jest"],
"typeRoots": ["./src/types", "./node_modules/@types"],
}
Run Code Online (Sandbox Code Playgroud)
module.exports = {
preset: 'ts-jest',
roots: ['<rootDir>/src'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
Run Code Online (Sandbox Code Playgroud)
{
"presets": [
["@babel/preset-env", {"targets": {"node": "current"}}],
"@babel/preset-typescript"
],
"plugins": ["@babel/transform-runtime"]
}
Run Code Online (Sandbox Code Playgroud)
我的测试运行良好npm run test
,但这仍然是一个恼人的问题,我想这只是./
我的配置之一或其他内容中的缺失。虽然打字稿/笑话有点新鲜,但可能是别的东西。希望我提供了足够的信息,但如果有必要,我很乐意添加更多信息 任何帮助将不胜感激,干杯
小智 4
我不是专家,但在修改 typeRoots 属性后,我遇到了同样的问题(尽管设置不同),并且我能够通过在“types”属性中包含“@types/jest”来使其工作tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./",
"strict": true,
"typeRoots": [
"./node_modules/@types/",
"./src/@types/"
],
"types": ["jest", "node", "@types/jest"],
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules"],
"include": ["./src/**/*.tsx", "./src/**/*.ts"]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9582 次 |
最近记录: |