[Bug]: jest fails with @react-native/polyfills/error-guard.js
Version
28.1.2
Steps to reproduce
jest.config.js
module.exports = {
preset: 'react-native',
// setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!(@react-native|react-native)/)',
'/node_modules/(?!(react-native|@react-native|@react-navigation/.*|@react-native-async-storage|react-native-gesture-handler)/.*)',
'/node_modules/(?!(react-native-cookies|@sentry/react-native)/)',
],
setupFiles: [
'./node_modules/react-native-gesture-handler/jestSetup.js',
'<rootDir>/jest.setup.js',
],
moduleNameMapper: {
'\\.svg': '<rootDir>/__mocks__/svgMock.js',
},
collectCoverage: false,
coverageDirectory: '__coverage__',
coveragePathIgnorePatterns: ['/node_modules/', '.*.svg', '.*.png'],
watchPathIgnorePatterns: ['<rootDir>/node_modules/'],
}
Expected behavior
Expected tests workf fine
Actual behavior
node_modules/@react-native/polyfills/error-guard.js:14
type ErrorHandler = (error: mixed, isFatal: boolean) => void;
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
at Object.<anonymous> (node_modules/react-native/jest/setup.js:16:6)
Additional context
I try all the solutions. I've tying for days and i always got the same problem.
Environment
System:
OS: macOS 12.4
CPU: (8) arm64 Apple M1
Binaries:
Node: 16.15.0 - /opt/homebrew/opt/node@16/bin/node
Yarn: 1.22.18 - /opt/homebrew/bin/yarn
npm: 8.5.5 - /opt/homebrew/opt/node@16/bin/npm
npmPackages:
jest: ^28.1.2 => 28.1.2
I'm facing the same issue, @daviseares have you found a solution?
SyntaxError: /Users/.../node_modules/@react-native/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;
16 |
17 | /**
Environment
System:
OS: macOS 12.4
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn
npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
npmPackages:
jest: ^28.1.3 => 28.1.3
edit: This looks like a bug from the react-native package: https://github.com/facebook/react-native/issues/33426
Any update on this issue
node_modules shouldn't have to be transpiled - unfortunately that seems to be the norm in RN. You probably need to adjust transformIgnorePatterns: https://jestjs.io/docs/configuration#transformignorepatterns-arraystring
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.