Not processing correctly when using es2015 modules
See original GitHub issueRelates to #99
When using es2015 modules (necessary for example for tree-shaking), ts-jest throws an error not recognizing import
statement. Such configuration can be:
{
"compilerOptions": {
"moduleResolution": "node",
"target": "es6",
...
But when you use commonjs modules, it works
{
"compilerOptions": {
"module": "commonjs"
"moduleResolution": "node",
"target": "es6",
...
How to reproduce
git clone -b ts-jest-issue https://github.com/alexjoverm/typescript-library-starter.git
cd typescript-library-starter
npm install # give it the name "library" when asked
npm t
It will throw a SyntaxError: Unexpected token import
Now go to tsconfig.json
and add "module": "commonjs"
to the compilerOptions
property.
Execute npm t -- --no-cache
Then it works
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
javascript - ES2015 not compiled correctly - Stack Overflow
I have this line in a .jsx file in my react project: import React, {Component} from 'react';. However, this is not compiled correctly...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >16. Modules - Exploring JS
Programmatically work with modules; Configure module loading. The module loader API is not part of the ES6 standard #. It will be specified...
Read more >Modules, introduction - The Modern JavaScript Tutorial
A module is just a file. One script is one module. As simple as that. Modules can load each other and use special...
Read more >Documentation - Modules - TypeScript
declared in a module are not visible outside the module unless they are explicitly exported using one of the export forms. Conversely, to...
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
Ok, understood. I think I’ve done it in jest but you need babel-jest and all that stuff if I remember correctly.
If that’s the case, probably is better to add it to https://github.com/kulshekhar/ts-jest#known-limitations-for-ts-compiler-options?? Then other people don’t stumble into the same issue
@kulshekhar @alexjoverm isn’t this commit introduced a regression to related PR #123? https://github.com/kulshekhar/ts-jest/commit/d26dbf6ff0b10a1a30f74274caef67e55d43bc29#diff-e1495d267619047a7cca5cfe8f692729L85
I have the same issue as OP, from what I understood the change was suppose to always override module entry, no matter if
tsconfig
is loaded from root folder or other folder likesrc/
in my case. I think the change from the commit changed to work only fortsconfig
loaded from root folder. This change has broken my test config after the update.My config:
I have created a new issue to track this: https://github.com/kulshekhar/ts-jest/issues/161