After react-native bump to 71.0, "Cannot find module 'typeorm''

165 Views Asked by At

After bumping our expo app to expo SDK 48 (which importantly includes the react-native bump 0.70.13 -> 0.71.0), when running our previously passing jest suite, we started encounting the error:

"Cannot find module 'typeorm' from '<one of my typeorm objects>.ts'"

It's important to note that our app build still works as expected.

I narrowed down the issue to be only associated w/ the react-native dependency bump, with all relevant expo dependencies on their 48.x versions.

Has anyone else encounted time issue?

Here is my jest configuration in package.json:

  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@sentry/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|i18n-js)"
    ],
    "setupFiles": [
      "./jest.setup.js"
    ]
  },

I've tried many things:

  • Updating ignore patterns to include typeorm: transformIgnorePatterns
  • Experimenting w/ the jest setting 'moduleNameMapper`
  • Upgrading to SDK 49 to see if this solves the issue
1

There are 1 best solutions below

0
DLawler On BEST ANSWER

I'm answering my own question after hours of debugging.

Included in the changelog of react native 71.0 is a reference to the JSCRuntime moved to react-jsc. I'm assuming this runtime change along with my current configuration is responsible (somehow) for the now inability of jest to retrieve modules.

What ended up working was adding "testEnvironment": "node" to our jest config in package.json, like so:

"jest": {
    "preset": "jest-expo",
    "testEnvironment": "node",
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@sentry/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|i18n-js)"
    ],
    "setupFiles": [
      "./jest.setup.js"
    ]
  },

Why this works, I can only guess, but I hope it helps someone else!