nx
nx copied to clipboard
React Native tests not working in PNPM workspace
Current Behavior
Running tests in a freshly generated component or app does not work out of the box, error
.pnpm/@[email protected]/node_modules/@react-native/polyfills/error-guard.js:14
type ErrorHandler = (error: mixed, isFatal: boolean) => void;
Expected Behavior
Expect tests to pass
GitHub Repo
https://github.com/Tobbb/NxBug
Steps to Reproduce
- run
nx run mob-asd:test
Nx Report
Node : 20.2.0
OS : darwin x64
pnpm : 8.6.1
Hasher : Native
nx : 16.3.2
@nx/js : 16.3.2
@nx/jest : 16.3.2
@nx/linter : 16.3.2
@nx/workspace : 16.3.2
@nx/detox : 16.3.2
@nx/devkit : 16.3.2
@nx/eslint-plugin : 16.3.2
@nx/react : 16.3.2
@nx/react-native : 16.3.2
@nrwl/tao : 16.3.2
@nx/web : 16.3.2
typescript : 5.0.2
Failure Logs
.pnpm/@[email protected]/node_modules/@react-native/polyfills/error-guard.js:14
type ErrorHandler = (error: mixed, isFatal: boolean) => void;
Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
to fix the issue install @babel/plugin-proposal-class-properties,@babel/plugin-transform-private-methods.
add
transformIgnorePatterns: ['node_modules/(?!react-native)/'],
to jest.config.ts
add "plugins": ["@babel/plugin-proposal-class-properties","@babel/plugin-transform-private-methods"] to babel.config.json
sadly @babel/plugin-proposal-class-properties","@babel/plugin-transform-private-methods causing build fails. so this is not the solution
@Tobbb i figure out how to solve this issue. it is something with transformIgnorePatterns. however, its regex needs to be:
transformIgnorePatterns: [
'node_modules/(?!((.pnpm/)?((jest-)?react-native|@react-native(-community)?))|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)',
],
Then you also install @babel/runtime:
pnpm install @babel/runtime --save-dev
i will do a proper fix for this.
@xiongemi i noticed in your PR that the fix is only for expo, won't the same need to be added for the react-native generator?
Didn't get the above solution to work, however adding this to jest.config.ts just solves it :)
transformIgnorePatterns: ['node_modules/(?!react-native)/', 'jest-runner'],
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.