How to fix Jest failing with “Unexpected token *” on import statement with JavaScript?

Sometimes, we want to fix Jest failing with “Unexpected token *” on import statement with JavaScript.

In this article, we’ll look at how to fix Jest failing with “Unexpected token *” on import statement with JavaScript.

How to fix Jest failing with “Unexpected token *” on import statement with JavaScript?

To fix Jest failing with “Unexpected token *” on import statement with JavaScript, we transpile modules that cause the error.

For instance, we write

{
  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
    ]
  }
}

to add the transformIgnorePatterns property into the jest.config.js file.

We use transformIgnorePatterns to ignore the path patterns of the modules that don’t need to be transpiled.

Conclusion

To fix Jest failing with “Unexpected token *” on import statement with JavaScript, we transpile modules that cause the error.