在我的tsconfig中,我目前将模块compilerOption属性设置为"es6"但是,当我运行Jest时,我收到以下错误:
Test suite failed to run
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){require('ts-jest').install();import { User } from './models/user;
^^^^^^
SyntaxError: Unexpected token import
at transformAndBuildScript (node_modules\jest-runtime\build\transform.js:320:12)
at process._tickCallback (internal\process\next_tick.js:103:7)
Run Code Online (Sandbox Code Playgroud)
如果我将模块切换到"commonJS",那么测试运行正常.但是,我不应该这样做,因为babel插件"transform-es2015-modules-commonjs"应该将ES模块转换为commonJS(或者我的理解是不正确的?).
我怀疑我错误配置了一些小而重要的东西.任何人都可以指出我遇到麻烦的地方吗?
提前致谢.
.tsconfig
{
"compilerOptions": {
"module": "es6", // Changing this to "commonJS" resolves the error.
"target": "es6",
"moduleResolution": "node",
"baseUrl": "src",
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"sourceMap": true,
"outDir": "ts-build",
"jsx": "preserve",
"experimentalDecorators": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"filesGlob": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules",
"dist"
]
}
Run Code Online (Sandbox Code Playgroud)
.babelrc
{
"presets": [
"es2015",
"react", …Run Code Online (Sandbox Code Playgroud)