transformIgnorePatterns: [],
Just adding this line with an empty array is the simplest answer which worked.
I was upgrading a project that uses a version of babel that reads the config from .babelrc
, when I upgraded to a newer version I read:
https://babeljs.io/docs/en/configuration#whats-your-use-case
What's your use case?
You are using a monorepo?
You want to compile node_modules?
babel.config.json is for you!
On top of:
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!(module))"
I renamed .babelrc
to babel.config.json
too.
"modules": "commonjs", // <- Check and see if you have this line
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
"stage-2"
"plugins": ["transform-vue-jsx", "transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
jest understands commonJs so it needs babel to transform the code for it before use. Also jest uses caching when running code. So make sure you run jest --clearCache
before running jest.
Tested Environment:
Node v8.13.0
Babel v6+
Jest v27
I'm using a monorepo (it contains multiple packages for the frontend and backend).
The package I'm testing imports a file from another package that uses the dependency uuid
.
All the files are in Typescript (not Javascript).
The package I'm testing has a tsconfig file for testing only, called tsconfig.test.json
. It has the properties commonjs
and allowJs
. Adding allowJs
solves the problem when importing uuid
, I don't know why.
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": [
"jest",
"node"
// Necessary to import dependency uuid using CommonJS
"allowJs": true
"include": [
"jest.config.ts",
"**/*.test.ts",
"**/*.d.ts"
I got same error. Library A gave such error. I did not use this library in my code directly. I played with jest config a lot of time.
But I found that I forget to mock library B in ...test.tsx file. After mocking there was not that error. Sounds pretty stupid but it works for me.
I had the same problem after upgrading 2 projects from Angular 12 to Angular 14 and 15.
After much searching, the ONLY thing that turned both projects in good ones again was by upgrading the 'Rxjs' package to a newer/newest version. The ONLY thing.
Be sure to have that RxJs upgraded. After that I made sure to have the tslib upgraded as well.
The base Jest configuration was via this course.
I had the exact same problem when using jest 29.7.0 with React 18.
In my case this config worked after changing the .babelrc
into babel.config.js
module.exports = {
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!(module))"
SyntaxError: Unexpected token 'export'
I made sure my jest was properly installed and set up, as per Next.js docs, but still same issue. None of the popular solutions here were working for me either.
However, while running npm i
, I noticed this warning:
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '[email protected]',
npm WARN EBADENGINE required: { node: '>=18' },
npm WARN EBADENGINE current: { node: 'v16.19.1', npm: '8.19.3' }
npm WARN EBADENGINE }
Since version 6.0.0, the flat package is distributed in ECMAScript modules.
Solution
The quickest way to fix it was to downgrade it to a version that is compatible with my node.js and my project settings:
npm i flat@5
And since then I've been able to run jest as expected (perhaps updating the node.js version would've solved it too).
I had the same error of importing dataSet from vis-data.js library
import { DataSet } from 'vis-data/esnext';
So I just removed /esnext
from the path and now it works:
import { DataSet } from 'vis-data';
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.