Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError - node_modules/react-native/Libraries/polyfills/error-guard.js: Missing semicolon. (14:4) on running jest in react native library

I'm trying to setup jest for a react native library but I'm getting the below error

SyntaxError: react-native/Libraries/polyfills/error-guard.js: Missing semicolon. (14:4)

      12 | let _inGuard = 0;
      13 |
    > 14 | type ErrorHandler = (error: mixed, isFatal: boolean) => void;
         |     ^
      15 | type Fn<Args, Return> = (...Args) => Return;

react-native version : 0.61.5

app.js

import { Dimensions } from 'react-native';

function sum(a, b) {
    return a + b;
}
module.exports = sum;

app.test.js

const sum = require('./app');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

jest.config.js

module.exports ={
    preset : 'react-native',
    transformIgnorePatterns: [
        '/node_modules/(?!(@react-native|react-native)/).*/'
    ]
}

.babelrc

{
    "presets": ["react-native"]
}

I tried various solutions suggested like adding transformIgnorePatterns but to no avail. can someone help me here ?

like image 585
Murugappan Vr Avatar asked Dec 05 '25 15:12

Murugappan Vr


1 Answers

It worked for me after I changed the .babelrc file to babel.config.js.

like image 76
Daniel Buterus Avatar answered Dec 07 '25 07:12

Daniel Buterus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!