Clean Expo app gives uncaught error when running on iOS (Expo Go): Requiring unknown module 'undefined'

SDK version: 45.0.4 (but also SDK 44)
Platform: iOS

When I upgraded an existing app to SDK 44/45, I noticed this persisting bug after running my app on iOS (both simulator and device). To double check, I’ve created a new Expo app just now (SDK 45.0.4), and this completely clean app runs into the same code (also tried different iOS versions/devices).

I’ve tried all solutions suggested here and at other forums (including removing node_modules, installing react-native-screens to the dependencies, etc), but nothing seems to work.

Wondering if anyone else experiences the same issue and found a solution.

Error: Requiring unknown module "undefined". If you are sure the module exists, try restarting Metro. You may also want to run yarnornpm install. at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError at node_modules/metro-runtime/src/polyfills/require.js:203:6 in guardedLoadModule at node_modules/expo/build/launch/RecoveryProps.js:4:42 in attachRecoveredProps at node_modules/expo/build/launch/withExpoRoot.js:17:30 in ExpoRoot at node_modules/react-native/Libraries/ReactNative/renderApplication.js:76:4 in renderApplication at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:119:25 in runnables.appKey.run at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:213:4 in runApplication

Hi @jelleams

Could you please explain in detail the steps you went through which lead to the above error?

Hey @wodin,

Definitely!

The steps:

  1. expo init my-app
  2. cd my-app
  3. yarn
  4. expo start
  5. build on iOS (either through terminal or web)

Leads to this:

The package.json looks like this:

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo/metro-config": "^0.3.17",
    "expo": "~45.0.4",
    "expo-status-bar": "~1.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-web": "0.17.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.66.13",
    "typescript": "~4.3.5"
  },
  "private": true
}

And the expo-cli version I’m running is 5.4.6

Thanks!

Thanks

You’re choosing the blank (TypeScript) template, right?

What command do you run exactly when you build from the terminal? (I am also curious how you build on the web?)

Is the screenshot of the Expo Go app? If so, why do you need to build anything before opening the app in Expo Go?

EDIT: OK, I suppose you mean that you open the Expo Go app and it causes Metro to bundle the JS? I suppose you’re not running some command to build anything at this point, right?

Strangely, if I init a new app I do not get the above dependency. Everything else is identical.

If I init a new app, run expo start, press i to open the app in Expo Go in the Simulator everything works as expected except for one weird error which doesn’t seem to affect anything:

› Opening on iOS...
› Opening exp://192.168.1.123:19000 on iPhone 13
› Press ? │ show all commands
Error: ENOENT: no such file or directory, scandir '/private/tmp/blah/assets/icons'
iOS Bundling complete 10445ms
iOS Running app on iPhone 13

I can’t see where that ENOENT error is coming from. I can’t find anything referencing that path. But the app opens in Expo Go with the “Open up App.tsx to start working on your app!” message.

Wasn’t clear before about the exact steps (specifically building), but this is exactly what I do:

I just did it again with the same result (and indeed with the blank/typescript template). The “@expo/metro-config” package wasn’t added; must have been something I did myself previously. But I still see the same error.

Strange. Trying to think what it could be.

In case it helps, this is what expo-env-info says for me:

% npx expo-env-info

  expo-env-info 1.0.3 environment info:
    System:
      OS: macOS 12.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.15.0 - /opt/homebrew/opt/node@16/bin/node
      Yarn: 1.22.19 - /opt/homebrew/bin/yarn
      npm: 8.5.5 - /opt/homebrew/opt/node@16/bin/npm
    Managers:
      CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
    IDEs:
      Android Studio: 2020.3 AI-203.7717.56.2031.7935034
      Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
    npmPackages:
      expo: ~45.0.0 => 45.0.4
      react: 17.0.2 => 17.0.2
      react-dom: 17.0.2 => 17.0.2
      react-native: 0.68.2 => 0.68.2
      react-native-web: 0.17.7 => 0.17.7
    npmGlobalPackages:
      eas-cli: 0.52.0
      expo-cli: 5.4.6
    Expo Workflow: managed

What versions of expo-cli, node, etc. do you have?

Thanks!

Upgraded a bunch of stuff (like cocoapods and node), but unfortunately, no improvement - even after creating a new expo app.

  expo-env-info 1.0.3 environment info:
    System:
      OS: macOS 11.5.2
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.15.0 - /usr/local/bin/node
      Yarn: 1.22.19 - /opt/homebrew/bin/yarn
      npm: 8.8.0 - /opt/homebrew/bin/npm
      Watchman: 2022.05.16.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    IDEs:
      Android Studio: 4.1 AI-201.8743.12.41.7042882
      Xcode: 12.4/12D4e - /usr/bin/xcodebuild
    npmPackages:
      expo: ~45.0.0 => 45.0.4 
      react: 17.0.2 => 17.0.2 
      react-dom: 17.0.2 => 17.0.2 
      react-native: 0.68.2 => 0.68.2 
      react-native-web: 0.17.7 => 0.17.7 
    npmGlobalPackages:
      eas-cli: 0.41.0
    Expo Workflow: managed

My expo-cli is on 5.4.6. Currently upgrading MacOS and Xcode, but sceptic whether that will change anything.

I agree, but worth doing anyway.

How is expo-cli installed?

sudo npm install --global expo-cli

Unfortunately, it didn’t help. Also updated XCode, didn’t work.

At this point, I really wonder what is going wrong here - or what I could do/reset to prevent it from happening. Is there some way to see which module is being loaded (or which line of code is responsible for loading the ‘undefined’ module?

Perhaps useful information: I’ve create a clean react-native app (without expo), and there is no error like the one I encounter with the apps set up by expo.

can you share the project where you have this issue on github for us to try to reproduce?

@notbrent Sure! https://github.com/jelleag/ExpoBugTestProject

tried that out, can’t reproduce it on my machine. this seems like there must be some global node issue on your machine. can you try uninstalling node entirely, reinstalling, and running the project again?

Have done that three times, with different ways of installing node, but no changes. It shouldn’t matter that I’m using an M1 Mac, right?

right, that shouldn’t matter. out of curiosity, is there anything special about the folder that you are running this from? eg: is it in a dropbox synced directory?

No, not at all. Just a local folder.

Might it be a caching issue? I’ve been running expo r -c a couple of times already, not sure if there’s any other way to clear the cache.

Tried clearing the caches, but didn’t work. Then I deleted all modules, and performed clean install with npm - I know, should’ve tried this much sooner. Everything is working now and the bug is not showing up. I think it’s safe to say that the problem is caused by Yarn, even after clearing its caches.

Very strange.

I have encountered weird errors before when expo-cli was installed globally using yarn which were fixed when installing it with npm instead.

I’ve also recently seen someone on the forums who was having weird issues when he installed his dependencies with npm which were fixed by switching to yarn.

I use npm to install things like expo-cli and eas-cli globally. I use yarn to manage the dependencies in my apps. :person_shrugging:

EDIT: Oh, I have also run into a weird issue with yarn running out of memory when trying to upgrade an app to Expo SDK 45 from 44. This was “fixed” by removing yarn.lock and re-running yarn before trying the upgrade again.