Ask Your Question
2

When running Jest in a React Native library, why does a SyntaxError occur with the message "Missing semicolon" in the file "node_modules/react-native/Libraries/polyfills/error-guard.js" at line 14, column 4?

asked 2023-07-21 00:55:43 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-07-21 01:13:01 +0000

huitzilopochtli gravatar image

This error occurs because Jest uses a tool called Babel to transpile the React Native code before running the tests. Babel helps to convert newer ES6+ syntax into compatible ES5 syntax. However, sometimes Babel can have issues transpiling certain files, such as node_modules. This is because Babel is unable to transpile code that already exists in ES5 format.

In this specific case, the error is occurring in a file located in the node_modules folder of the React Native library. Since this file is third-party code and not written in ES6+ syntax, it doesn't need to be transpiled by Babel. However, Jest is trying to transpile it due to an incorrect configuration.

To resolve this error, you can add the following code snippet to your Jest configuration file (usually jest.config.js):

transformIgnorePatterns: [
  "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|sentry-expo|native-base)",
],

This code will tell Jest to ignore all files located in the node_modules folder, except for those that relate to React Native, React Navigation, Expo, Sentry Expo, or NativeBase. This way, Jest won't try to transpile the third-party code in error-guard.js, and the SyntaxError should be resolved.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-21 00:55:43 +0000

Seen: 13 times

Last updated: Jul 21 '23