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:
- Created 6 years ago
- Reactions:8
- Comments:17 (3 by maintainers)
Top 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 >
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 Free
Top 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

Anyone know any more recent updates on this issue? I know Babel 7 is released now.
@lyy011lyy Works for me too.
I also had to set
moduleDirectoriesin my jest config to something like this: