krotsky
krotsky

Reputation: 11

Jest throw error SyntaxError: Unexpected identifier

Jest config is:

module.exports = {
  transformIgnorePatterns: ['<rootDir>/node_modules/(?!(@react-native|react-native)/)'],
  preset: 'react-native',
  transform: {
    '^.+\\.js$': require.resolve('react-native/jest/preprocessor.js'),
  },
};

In babel config there is presets: ['module:metro-react-native-babel-preset'],

In package I have

"jest": "^24.9.0",
"react": "^16.14.0",
"react-native": "^0.64.0",

Versions of React and React-native are strict because of youi-tv

If I run jest I get an error:

SyntaxError: Unexpected identifier

node_modules/@react-native/polyfills/error-guard.js:14
type ErrorHandler = (error: mixed, isFatal: boolean) => void;

Also if I use ts-jest with configuration I can get such an error in my *.test.tsx

SyntaxError: Unexpected token '<'

Please any advice

Upvotes: 1

Views: 540

Answers (1)

user16252105
user16252105

Reputation: 11

For me the problem was that I used more than one string in the "transformIgnorePatterns" on the jest configuration in the package.json.

Upvotes: 1

Related Questions