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.

ts-jest fails to import .ts modules from outside project root

See original GitHub issue
  • Issue

ts-jest throws an error whenever a test utilizes a module from outside the project root.

ReferenceError: Unknown plugin "transform-es2015-modules-commonjs" specified in "base" at 0, attempted toresolve relative to "/home/colin/localdev/ts-jest-error/common"

      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:17
          at Array.map (<anonymous>)
  • Expected behavior

TS files should be correctly imported even from outside the project.

  • Link to a minimal repo that reproduces this issue

https://github.com/colinskow/ts-jest-transform-error

cd main && npm install && npm test

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
dyst5422commented, Jan 24, 2018

Anyone know any more recent updates on this issue? I know Babel 7 is released now.

2reactions
josdujcommented, Jun 30, 2018

@lyy011lyy Works for me too.

I also had to set moduleDirectories in my jest config to something like this:

"moduleDirectories": [
	"node_modules",
	"main/node_modules"
],
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Jest: Cannot use import statement outside module
The TypeScript jest error "Cannot use import statement outside module" occurs when we misconfigure jest in a TypeScript project and run test files...
Read more >
SyntaxError: Cannot use import statement outside a module ...
This is a React, Typescript, Webpack project. I am trying to test a module. But Jest won't transform the module to plain javascript...
Read more >
jest cannot use import statement outside a module - You.com
Jest doesn't support ES6 module and hence throwing this error when you ... Create a babel.config.json config in your project root and enable...
Read more >
Configuring Jest
This option tells Jest that all imported modules in your tests ... Use the <rootDir> string token to include the path to your...
Read more >
Typescript – How to solve the problem with unresolved path ...
... file (in the project rootDir). It needs to import a module using path aliases: ... npm WARN dev ts-jest@"^27.0.7" from the root...
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