nx icon indicating copy to clipboard operation
nx copied to clipboard

React Native tests not working in PNPM workspace

Open Tobbb opened this issue 2 years ago • 1 comments

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

  1. 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

Tobbb avatar Jun 14 '23 08:06 Tobbb

sadly @babel/plugin-proposal-class-properties","@babel/plugin-transform-private-methods causing build fails. so this is not the solution

Tobbb avatar Jun 14 '23 11:06 Tobbb

@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 avatar Jun 19 '23 21:06 xiongemi

@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?

Tobbb avatar Jun 22 '23 07:06 Tobbb

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'],

Tobbb avatar Jun 22 '23 09:06 Tobbb

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.

github-actions[bot] avatar Oct 22 '23 00:10 github-actions[bot]