ts-jest: regression of Unexpected token import when using es2015 modules
SyntaxError: Unexpected token import when using es2015 modules with following config:
//tsconfig
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
...
}
}
// jest
{
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"globals": {
"__TS_CONFIG__": "<rootDir>/src/tsconfig.json"
}
}
- Fix If following line is taken out of enclosing if statement, problem is fixed.
- Expected behavior
should set config.module = 'commonjs'; when loading external tsconfig with "module": "es2015"
- Actions
- add a new test case to prevent further regressions of this case: https://github.com/kulshekhar/ts-jest/blob/master/tests/__tests__/tsconfig-default.spec.ts#L87
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (11 by maintainers)
@kulshekhar count on me if you need help for that refactor, you’re not alone 😉 I’d like to help if I can
@kulshekhar I understand, this is not an easy work, I really appreciate your work don’t get me wrong, just wanted to suggest a way to improve it somehow, maybe it’s not the best solution but might be some direction to follow 😃
Suggested workaround is the best solution possible right now and should be fine for now, and I’m still open to help in the future.
In the worst case - suppose you need all these settings for testing as well - you could create a separate file for testing, like so:
and use this new file in
jest > globals > __TS_CONFIG__