How to use with target="es6"?
See original GitHub issueI use https://github.com/s-panferov/awesome-typescript-loader instead of ts-loader, which speeds up compilation. My current tsconfig.json is:
{
"compilerOptions": {
"noEmit": true,
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"jsx": "preserve",
"lib": ["dom","es5","es6","es7","es2017.object"]
},
"filesGlob": [
"./**/*.ts"
],
"exclude": [
"node_modules",
"build"
],
"awesomeTypescriptLoaderOptions": {
"useBabel": true,
"forkChecker": true,
"useCache": false
}
}
And my jest config is:
"jest": {
"collectCoverageFrom": [
"app/**/*.{js,jsx}",
"!app/app.js",
"!app/routes.js"
],
"moduleDirectories": [
"node_modules",
"<rootDir>/app"
],
"moduleNameMapper": {
".*\\.css$": "<rootDir>/mocks/cssModule.js",
".*\\.jpg$": "<rootDir>/mocks/image.js",
".*\\.svg$": "<rootDir>/mocks/svg.js"
},
"setupTestFrameworkScriptFile": "<rootDir>/internals/testing/test-bundler.js",
"testRegex": "tests/.*\\.test\\.(ts|tsx|js)$",
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
}
So my tests obviously fail with SyntaxError: Unexpected token import
.
How to handle this setup with ts-jest?
node: v.6.6.0 typescript: 2.0.8 ts-jest: 17.0.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:12 (7 by maintainers)
Top Results From Across the Web
TSConfig Option: target - TypeScript
Modern browsers support all ES6 features, so ES6 is a good choice. You might choose to set a lower target if your code...
Read more >What is target in tsconfig.json for? - Stack Overflow
Changing your target means changing the libraries with which your code compiles. If you want to keep the target a low version while...
Read more >Easy TypeScript: A Quick Guide to the target Option
The target option is configurable in your tsconfig.json or on the command-line via the --target flag. It refers to the JavaScript target that...
Read more >Typescript - selecting proper target version - Dancing with CRM
Learn why you should choose proper target version in your tsconfig file and how it boost your code.
Read more >ES6 Tutorial For Beginners - function.name and new.target
ES6 Tutorial For Beginners - function.name and new. target ... Make Obstacles And Restricted Areas In A Map Using Navigation Meshes ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kulshekhar, sorry for the late response. The import issue appeared at the time to come from a missing
transform
field in my config. Thetransform
issue was difficult to track down because I appeared to be seeing a new issue that when the config changed, either through a different file via--config
or when a consistently named config file itself changed, that the cache didn’t invalidate. I had planned to report the caching config issue as a standalone bug but unfortunately I can no longer reproduce it. For now, I apologize for the noise and will file a ticket if I can reproduce it again.First time user here. I seemed to have had a similar (?) issue with imports when I accidentally mangled my Jest config to omit
transform
. What really bit was me that the cache doesn’t invalidate when the config changes. You can really test your config by disabling it,jest --no-cache
. You can check out the recommended example config here. I found the import token error quite cryptic.