Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes #26570

Closed
k1h1a1n1u1m1a1n opened this issue Jan 21, 2024 · 26 comments
Labels
incomplete issue: missing or invalid repro A minimal reproducible example is required for most issues needs review Issue is ready to be reviewed by a maintainer

Comments

@k1h1a1n1u1m1a1n
Copy link

Minimal reproducible example

Android Bundling complete 13373ms ERROR TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes ERROR TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes ERROR Invariant Violation: "main" has not been registered. This can happen if: * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project. * A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes

Summary

Everything was working about 2 weeks ago, but now I'm getting errors. Nothing has changed in the code
image

Environment

expo-env-info 1.2.0 environment info:
System:
OS: Windows 10 10.0.19042
Binaries:
Node: 18.16.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: AI-223.8836.35.2231.11005911
npmPackages:
expo: ^49.0.21 => 49.0.22
expo-router: ^2.0.0 => 2.0.14
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.72.6 => 0.72.6
Expo Workflow: managed

@k1h1a1n1u1m1a1n k1h1a1n1u1m1a1n added the needs validation Issue needs to be validated label Jan 21, 2024
@expo-bot expo-bot added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels Jan 21, 2024
@k1h1a1n1u1m1a1n
Copy link
Author

Fixed by adding into my package.json

    "@expo/config-plugins": "7.2.2",
    "expo-constants": "~14.4.2",

@Elue-dev
Copy link

im having this issue now

@Ksalcant
Copy link

Ksalcant commented Jan 23, 2024

Mine worked by adding "@expo/config-plugins": "7.2.2",
"expo-constants": "~14.4.2",) and then running npx expo install --fix

@jianrontan
Copy link

I also just got this issue after i rm -rf my node_modules and package-lock.json and then npm install. It was working perfectly before this. However adding the "@expo/config-plugins": "7.2.2", did not work for me (i already have "expo-constants": "~14.4.2",).

@Elue-dev
Copy link

this is exactly what happend, was working fine till i had to remove node modules and re install, i’m using Node 18 and i already have expo config plugin installed as we as expo constants, do i have to uninstall and install again?

@k1h1a1n1u1m1a1n
Copy link
Author

@jianrontan Try npx expo-doctor
Any errors here?

@Elue-dev
Copy link

@jianrontan Try npx expo-doctor Any errors here?

alright will try this

@jianrontan
Copy link

I actually managed to (temporarily i guess) fix the issue by replacing my package-lock.json with the one from a previous commit and then npm installing the node modules. I will try to do npx expo-doctor with the faulty package-lock.json.

@ujangaripin24
Copy link

npx expo install --fix

thx work for me

@Elue-dev
Copy link

Mine worked by adding "@expo/config-plugins": "7.2.2", "expo-constants": "~14.4.2",) and then running npx expo install --fix

this ended up working for me, adding @expo/config-pligins and running npx expo install —fix solved the issue, thanks👌🏽

@jianrontan
Copy link

It still doesn't work for me. I ran npx expo-doctor and found out a dependency was using @expo/config-plugins 7.8.4 so i added the below to my package.json and then reinstalled everything:
"overrides": {
"@expo/config-plugins": "~7.2.2"
},
This still didnt do the trick. I ran npx expo install --fix afterwards and it said Dependencies are all up to date too. npx expo-doctor now shows all checks too so im out of ideas besides using the package-lock.json from my old commit. Anyone have any other solutions to fix this?

@Elue-dev
Copy link

It still doesn't work for me. I ran npx expo-doctor and found out a dependency was using @expo/config-plugins 7.8.4 so i added the below to my package.json and then reinstalled everything: "overrides": { "@expo/config-plugins": "~7.2.2" }, This still didnt do the trick. I ran npx expo install --fix afterwards and it said Dependencies are all up to date too. npx expo-doctor now shows all checks too so im out of ideas besides using the package-lock.json from my old commit. Anyone have any other solutions to fix this?

can you try installing expo constants, or please screenshot the error on your device, sometimes it adds the package causing the issue in it so it can help debug further

also try deleting node modules and package lock and running npx expo install again to see if it helps

@fiuzagr
Copy link

fiuzagr commented Jan 25, 2024

I had the same problem. After installing the expo-constants@~14.4.2 package, it started working without any issues. It was not necessary to install the @expo/config-plugins package.

@brentvatne brentvatne added the incomplete issue: missing or invalid repro A minimal reproducible example is required for most issues label Jan 26, 2024
@expo-bot
Copy link
Collaborator

Hi there! It looks like your issue requires a minimal reproducible example, but it is invalid or absent. Please prepare such an example and share it in a new issue.

The best way to get attention to your issue is to provide a clean and easy way for a developer to reproduce the issue on their own machine. Please do not provide your entire project, or a project with more code than is necessary to reproduce the issue.

A side benefit of going through the process of narrowing down the minimal amount of code needed to reproduce the issue is that you may get lucky and discover that the bug is due to a mistake in your application code that you can quickly fix on your own.

Resources

Common concerns

"I've only been able to reproduce it in private, proprietary code"

You may not have spent enough time narrowing down the root cause of the issue. Try out the techniques discussed in this manual debugging guide to learn how to isolate the problem from the rest of your codebase.

"I didn't have time to create one"

That's understandable, it can take some time to prepare. We ask that you hold off on filing an issue until you are able to fully complete the required fields in the issue template.

"You can reproduce it by yourself by creating a project and following these steps"

This is useful knowledge, but it's still valuable to have the resulting project that is produced from running the steps, where you have verified you can reproduce the issue.

@brentvatne
Copy link
Member

hey there! we're happy to help out if we can get a minimal reproducible example. i suspect if you run npx expo-doctor@latest you will see some warnings if this is happening for you. you should not need to install @expo/config-plugins directly into your project, it is a dependency of the expo package, and if you are installing it then that's a red flag that there may be some other underlying issue that npx expo-doctor@latest will point to

@troystark
Copy link

troystark commented Jan 27, 2024

@brentvatne

This is my output:

Expected package @expo/config-plugins@~7.2.2
Found invalid:
  @expo/config-plugins@7.8.4
  (for more info, run: npm why @expo/config-plugins)
Some dependencies are incompatible with the installed expo version:
  expo-constants@15.4.5 - expected version: ~14.4.2
Your project may not work correctly until you install the correct versions of the packages.
Fix with: npx expo install --fix
Found outdated dependencies
One or more checks failed, indicating possible issues with the project.

Running npx expo install --fix appears to have corrected my problem.

For context I started my project with:
npx create-expo-app myProj -t tabs@49

Received these errors when running npx expo. I made no changes to the project after expo generated it.

iOS Bundling complete 9624ms
 ERROR  TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes
 ERROR  TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes
 ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

Since running the fix I can successfully run the app in the iOS simulator. Thanks for your help!

@troystark
Copy link

@brentvatne
I'm not sure what has changed, but expo doctor no longer suggests a fix and npx expo install --fix no longer works to correct the issue:

:~/$ npx create-expo-app -t tabs@49
...
✅ Your project is ready!
...
:~/$ npx expo-doctor@latest
✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that packages match versions required by installed Expo SDK
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✖ Check that native modules use compatible support package versions for installed Expo SDK

Detailed check results:

Expected package @expo/config-plugins@~7.2.2
Found invalid:
  @expo/config-plugins@7.8.4
  (for more info, run: npm why @expo/config-plugins)
Advice: Upgrade dependencies that are using the invalid package versions.

One or more checks failed, indicating possible issues with the project.
:~/$ npx expo install --fix
Dependencies are up to date

Would you have any suggestions for the correct method to remove/fix the package error?

@EvanBacon
Copy link
Contributor

I've published a new version of Router v2 (2.0.15) https://www.npmjs.com/package/expo-router/v/2.0.15 which has less forceful dependency versions.

@tofujlg
Copy link

tofujlg commented Feb 14, 2024

I ran npx expo-doctor@latest and fixed all the issue listed out.
The error TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes E.... does not show up anymore but I can no longer build the debug bundle.

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':react-native-screens:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

@MatkoMilic
Copy link

I lost a day or two on this and nothing was helping, and then I went again through all the old commits and I tried to remove all the new packages one by one and the one that finally solved it for me is removing expo module scripts:

"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.2.14",
"@types/react-native-vector-icons": "^6.4.18",
"expo-module-scripts": "^3.4.1",
"typescript": "^5.1.3"
},

So basically running npm uninstall expo-module-scripts solved it for me.

@mk6488
Copy link

mk6488 commented Mar 1, 2024

I have the same issue as everybody else is having. As soon as I wrap my app/_layout.tsx with the ClerkProvider I get the same error message as everybody else does:
TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes
at ContextNavigator (http://192.168.0.9:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true:152120:24)

I've been racking my brains for almost a week now. I've tried all the solutions mentioned above but nothing is fixing the problem.

@jamm59
Copy link

jamm59 commented Mar 3, 2024

Got mine to work by;

  1. using expo doctor: npx expo-doctor@latest
  2. expo doctor told me what packages I needed to take out of my package.json file (make sure to read the output from expo-doctor thoroughly)
  3. deleted the node_modules folder
  4. finally, yarn install && yarn start

Hope it works out for anyone else facing this issue

@Supsource
Copy link

I tried, all the fixes above, but still the same, anyone can help?
` ERROR TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes
ERROR Invariant Violation: "main" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes`

@NeelGaji
Copy link

I tried, all the fixes above, but still the same, anyone can help? ` ERROR TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes ERROR Invariant Violation: "main" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes`

I am facing the same issue and have tried all the above fixes. Is your error resolved?

@Supsource
Copy link

I tried, all the fixes above, but still the same, anyone can help? ` ERROR TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes ERROR Invariant Violation: "main" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes`

I am facing the same issue and have tried all the above fixes. Is your error resolved?

after searching for hours I found the exact problem I was facing, clerk/javascript#2650
As a commenter named @hughgardiner mentioned Installing the latest version of "expo-modules-core": "~1.11.8" might help, and I did the same & this solved my problem and now it's working smoothly.

@statico
Copy link

statico commented May 8, 2024

FWIW, I'm getting something similar with Clerk and Expo v51. As soon as I try to use a <ClerkLoaded> or <ClerkLoading> component, I get TypeError: 0, import_react6.useAssertWrappedByClerkProvider is not a function (it is undefined)

  • npx expo install --fix says Dependencies are up to date and makes no changes
  • npx expo-doctor@latest says Didn't find any issues with the project!
  • pnpm why expo-modules-core says everything is using expo-modules-core 1.12.9
  • I've deleted all node_modules dirs and rebuilt the app for the simulator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incomplete issue: missing or invalid repro A minimal reproducible example is required for most issues needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests