infinitered / ignite

Infinite Red's battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more!
MIT License
17.42k stars 1.38k forks source link

React Native 0.71.7 Jest config breaks with Node 18.16.1 #2520

Closed coolsoftwaretyler closed 9 months ago

coolsoftwaretyler commented 11 months ago

Describe the bug

It looks like y'all have seen this in CI, which references the React Native issue: https://github.com/facebook/react-native/issues/36440

On a fresh:

npx ignite-cli@latest new ContractRummy

After dependency installations, I get this error with yarn test on Node v18.16.1:

yarn run v1.22.11
$ jest
 FAIL  test/i18n.test.ts
  ● Test suite failed to run

    TypeError: Cannot redefine property: performance

      at Object.<anonymous> (node_modules/react-native/jest/setup.js:407:20)

 FAIL  app/services/api/apiProblem.test.ts
  ● Test suite failed to run

    TypeError: Cannot redefine property: performance

      at Object.<anonymous> (node_modules/react-native/jest/setup.js:407:20)

 FAIL  app/models/Episode.test.ts
  ● Test suite failed to run

    TypeError: Cannot redefine property: performance

      at Object.<anonymous> (node_modules/react-native/jest/setup.js:407:20)

 FAIL  app/utils/storage/storage.test.ts
  ● Test suite failed to run

    TypeError: Cannot redefine property: performance

      at Object.<anonymous> (node_modules/react-native/jest/setup.js:407:20)

Test Suites: 4 failed, 4 total
Tests:       0 total
Snapshots:   0 total
Time:        2.656 s
Ran all test suites.
error Command failed with exit code 1.

I was wondering if it makes sense to either:

  1. Include some kind of Node version check for compatibility
  2. Include a patch-package, like StackOverflow recommends

Ignite version

8.9.1

Additional info

System platform darwin
arch x64
cpu 8 cores Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz directory ContractRummy /Users/tylerwilliams/ContractRummy

JavaScript (and globally-installed packages) node 18.16.1 /Users/tylerwilliams/.asdf/installs/nodejs/18.16.1/bin/node npm 9.5.1 /Users/tylerwilliams/.asdf/plugins/nodejs/shims/npm
corepack 0.17.0
npm 9.5.1
yarn 1.22.11 /Users/tylerwilliams/.asdf/shims/yarn
create-vite 4.4.1
pnpm - not installed
expo 48.0.20 managed

Ignite ignite-cli 8.5.1 /Users/tylerwilliams/.npm/_npx/e31027f3785124a8/node_modules/.bin/ignite
ignite src build /Users/tylerwilliams/.npm/_npx/e31027f3785124a8/node_modules/ignite-cli/build

Android java 11.0.15 /Users/tylerwilliams/.asdf/shims/java android home - undefined

iOS xcode 15.0
cocoapods 1.12.1 /Users/tylerwilliams/.asdf/shims/pod

Tools git git version 2.42.0 /usr/local/bin/git

coolsoftwaretyler commented 11 months ago

I'm just going to roll back to node version 18.15.0, so no worries if y'all want to close this in favor of React Native fixing whatever's broken on their end.

frankcalise commented 11 months ago

Thanks Tyler, we had added the engine check earlier in the year but didn't realize it broke at 18.16 and up. I can look to modify it for now - perhaps see what I can do to fix this upstream in RN.

coolsoftwaretyler commented 11 months ago

Thanks!

frankcalise commented 11 months ago

It's interesting, I was trying to setup the node engines check as per the documentation, but I feel like the compare is off.

What I was trying with my current setup: Installed versions of node: 16.14.2, 18.2.0 and 18.11.0

If I go with this package json config and use 18.11.0 I fail.

  "engines": {
    "node": ">18.2 <18.2"
  },

What I wanted to end up doing was something like:

  "engines": {
    "node": ">=16 <18.16 >18.16"
  },

Now I suppose 16 is EOL at this point, so I can drop the third parameter which I thought was giving me trouble and move towards a config:

  "engines": {
    "node": "<18.16 >18.16" // or reverse these, didn't matter
  },

But that throws Expected version "<18.16 >18.16". Got "18.18.2" in the case of 18.18.2 being installed. Am I way off here?

coolsoftwaretyler commented 11 months ago

@frankcalise - I think you want:

"engines": {
  "node": "<18.16 || >18.16"
},

That should exclude 18.16.x.

https://stackoverflow.com/a/53071208

frankcalise commented 11 months ago

@coolsoftwaretyler yeah I tried that, it doesn't prevent you from installing with that version

coolsoftwaretyler commented 11 months ago

@frankcalise - would putting engine-strict=true in the .npmrc file fix this?

It's weird that you're getting errors for the other patterns and not this even without that setting. But I don't see it in the boilerplate, so maybe this would just force the issue?

frankcalise commented 9 months ago

I checked this over upstream with RN and it was a node related issue that was fixed in later versions of 18 and 19.

See https://github.com/facebook/react-native/issues/36440 for more info