question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

regression of Unexpected token import when using es2015 modules

See original GitHub issue
  • Issue regression of previously resolved issue #121 #123

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.

https://github.com/kulshekhar/ts-jest/commit/d26dbf6ff0b10a1a30f74274caef67e55d43bc29#diff-e1495d267619047a7cca5cfe8f692729R88

  • Expected behavior

should set config.module = 'commonjs'; when loading external tsconfig with "module": "es2015"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
alexjovermcommented, Apr 13, 2017

@kulshekhar count on me if you need help for that refactor, you’re not alone 😉 I’d like to help if I can

1reaction
piotrwitekcommented, Apr 9, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected Token Import for ES6 modules · Issue #2081
It seems that Jest is missing the babel configuration in my package.json and the test suite is failing with 'Unexpected Token Import'.
Read more >
Jest not parsing es6: SyntaxError: Unexpected token import
Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not...
Read more >
SyntaxError: Unexpected token import in Node.js
The "SyntaxError: Unexpected token import" occurs when we use the ES6 import syntax in a version of Node that doesn't support it. To...
Read more >
Node 13 must use import to load es module - Seba Online
You might get errors like SyntaxError: Unexpected token. ... Node 12 implemented ES6 modules If you worked with both React and Node, you...
Read more >
unexpected token, expected "," jest
It's trying to use ES modules syntax (import / export) but to do that, it needs to declare ... Unexpected token, expected ";"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found