Categories
TypeScript Answers

How to fix TypeScript ts-jest not recognizing ES6 imports?

Spread the love

Sometimes, we want to fix TypeScript ts-jest not recognizing ES6 imports.

In this article, we’ll look at how to fix TypeScript ts-jest not recognizing ES6 imports.

How to fix TypeScript ts-jest not recognizing ES6 imports?

To fix TypeScript ts-jest not recognizing ES6 imports, we need to transform ES6 modules into something Jest can use.

For instance, we write

{
  "jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest",
      "^.+\\.tsx?$": "ts-jest"
    }
    // ...
  }
}

in our Jest config file to transform jsx files with babel-jest so they can be run with

"^.+\\.jsx?$": "babel-jest"

Conclusion

To fix TypeScript ts-jest not recognizing ES6 imports, we need to transform ES6 modules into something Jest can use.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *