这是一个奇怪的错误。所以我将 jest 更新为 27 并且都停止工作
导入路径似乎有问题。所以以下
import { something } form 'src/app/components/.....';
不起作用,但这确实:
import { something } from '../../components/....';
我猜这是在 tsconfig 中管理的。这是我的spec
tsconfig:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jest", // 1
"node",
"Chrome"
],
"esModuleInterop": true, // 2
"emitDecoratorMetadata": true, // 3
"allowSyntheticDefaultImports": true,
},
"files": ["src/test.ts", "src/polyfills.ts"],
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
和主要的tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": ["es2018", "dom"],
"types": [],
"paths": {
"@shared/*": ["src/shared/*"]
},
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noEmitHelpers": false
},
"files": ["src/main.ts", "src/polyfills.ts"],
"angularCompilerOptions": {
"strictTemplates": true,
"fullTemplateTypeCheck": true
}
}
任何可能导致此导入问题的建议