-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not processing correctly when using es2015 modules #121
Comments
I followed your instructions and What version of node are you using? |
Sorry, forgot to update the actual test. Can you try again? Just update library.test.js with: import { DummyClass } from '../src/library'
/**
* Dummy test
*/
describe('Dummy test', () => {
it('works if true is truthy', () => {
expect(true).toBeTruthy()
})
it('DummyClass is instantiable', () => {
expect(new DummyClass()).toBeInstanceOf(DummyClass)
})
}) |
try adding the following in the "globals": {
"__TS_CONFIG__": {
"module": "commonjs"
}
} and change export default class DummyClass {
} to export class DummyClass {
} |
Yep, I fixed it by adding the first thing. The |
It's not a workaround. The output of |
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 |
I can understand adding babel in the final compilation (for production) stage but all adding babel in This isn't really a limitation of the ts-jest or of typescript. Either will happily process any valid module type. The error was thrown by jest. I agree about the possibility of confusion here. What could be done is prevent external settings from overriding the btw, you can close this if your issue has been solved :) |
Hey @kulshekhar, sorry I've been away some days. I didn't mean using Babel, I was just saying, forget about that :P IMO, it is a responsability of ts-jest. I mean, the error is triggered from jest, but is caused by the compilation from TS to JS. For me, 2 possible solutions:
What do you think? |
I could help here if you need btw |
@alexjoverm The way I see it, what happens between ts-jest and jest shouldn't be the user's concern. So while currently they can set the I can't think of a drawback of hard-coding If done this way, we'll need to add a note in the Options section in the readme that the value for This should be a simple PR if you choose to take it on :) |
I agree with your point of view. Sure, I'll take a look this weekend and go for it. Should we re-open the issue then? |
I've added another issue to track this - #122 |
@kulshekhar @alexjoverm isn't this commit introduced a regression to related PR #123? I have the same issue as OP, from what I understood the change was suppose to always override module entry, no matter if My config: // jest
{
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"globals": {
"__TS_CONFIG__": "<rootDir>/src/tsconfig.json"
}
}
//tsconfig
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
...
}
} I have created a new issue to track this: #161 |
Relates 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:But when you use commonjs modules, it works
How to reproduce
It will throw a
SyntaxError: Unexpected token import
Now go to
tsconfig.json
and add"module": "commonjs"
to thecompilerOptions
property.Execute
npm t -- --no-cache
Then it works
The text was updated successfully, but these errors were encountered: