facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.44k stars 24.37k forks source link

[Windows] 0.76.0 and 0.76.1 Turbo Module Error EarlyJsError: TurboModuleRegistry.getEnforcing(...) [module name] could not be found. Verify that a module by this name registered in the native binary #47403

Open CodeWithBlaze opened 3 weeks ago

CodeWithBlaze commented 3 weeks ago

Description

When created a Turbo Module with exact same steps as mention in React Native Official Docs, the app builds but then shows the error EarlyJsError: TurboModuleRegistry.getEnforcing(...) [module name] could not be found. Verify that a module by this name registered in the native binary.

Note: Platform is windows 11 (the react native app folder is already in exclusion from windows defender) Running on a physical device : Realme 11 pro 5g (Android 14) mode: developement

WhatsApp Image 2024-11-05 at 9 52 11 AM

Steps to reproduce

1) git clone https://github.com/CodeWithBlaze/TurboModuleExampleWIthError 2) npm install 3) npm run android

React Native Version

0.76.0

Affected Platforms

Runtime - Android

Areas

TurboModule - The New Native Module System

Output of npx react-native info

System:
  OS: Windows 11 10.0.22631
  CPU: (8) x64 Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
  Memory: 523.30 MB / 7.84 GB
Binaries:
  Node:
    version: 20.13.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.18
    path: ~\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 10.8.1
    path: ~\AppData\Roaming\npm\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: Version     2020.3.0.0 AI-203.7717.56.2031.7678000
  Visual Studio: Not Found
Languages:
  Java: javac 17
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0-alpha.2
    wanted: 15.0.0-alpha.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.0
    wanted: 0.76.0
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

EarlyJsError:

TurboModuleRegistry.getEnforcing(...): 'NativeLocalStorage' could not be found.

Verify that a module by this name is registered in the native binary., stack: invariant@2006:26

getEnforcing@2700:28

anonymous@104125:81

loadModulelmplementation@267:14

guardedLoadModule@175:38

metroRequire@89:92

anonymous@104044:63

loadModulelmplementation@267:14

guardedLoadModule@175:38

metroRequire@89:92

anonymous@1112:48

loadModulelmplementation@267:14

guardedLoadModule@168:47

metroRequire@89:92

global@104135:4

Reproducer

https://github.com/CodeWithBlaze/TurboModuleExampleWIthError

Screenshots and Videos

WhatsApp Image 2024-11-05 at 9 52 11 AM

react-native-bot commented 3 weeks ago
:warning: Newer Version of React Native is Available!
:information_source: You are on a supported minor version, but it looks like there's a newer patch available - 0.76.1. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
react-native-bot commented 3 weeks ago
:warning: Newer Version of React Native is Available!
:information_source: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
cortinico commented 2 weeks ago

@CodeWithBlaze can you share your full build log?

CodeWithBlaze commented 2 weeks ago

@cortinico Thank you for adressing the issue so quickly sure i can provide build logs

> TurboModuleExample@0.0.1 start
> react-native start

info Welcome to React Native v0.76
info Starting dev server on port 8081...

                        ▒▒▓▓▓▓▒▒
                     ▒▓▓▓▒▒░░▒▒▓▓▓▒
                  ▒▓▓▓▓░░░▒▒▒▒░░░▓▓▓▓▒
                 ▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓
                 ▓▓░░░░░▒▓▓▓▓▓▓▒░░░░░▓▓
                 ▓▓░░▓▓▒░░░▒▒░░░▒▓▒░░▓▓
                 ▓▓░░▓▓▓▓▓▒▒▒▒▓▓▓▓▒░░▓▓
                 ▓▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓
                 ▓▓▒░░▒▒▓▓▓▓▓▓▓▓▒░░░▒▓▓
                  ▒▓▓▓▒░░░▒▓▓▒░░░▒▓▓▓▒
                     ▒▓▓▓▒░░░░▒▓▓▓▒
                        ▒▒▓▓▓▓▒▒

                Welcome to Metro v0.81.0
              Fast - Scalable - Integrated

info Dev server ready

i - run on iOS
a - run on Android
r - reload app
d - open Dev Menu
j - open DevTools

info Opening app on Android...
info A dev server is already running for this project on port 8081.
info Installing the app...
> Task :gradle-plugin:settings-plugin:checkKotlinGradlePluginConfigurationErrors
> Task :gradle-plugin:shared:checkKotlinGradlePluginConfigurationErrors
> Task :gradle-plugin:shared:compileKotlin UP-TO-DATE
> Task :gradle-plugin:shared:compileJava NO-SOURCE
> Task :gradle-plugin:shared:processResources NO-SOURCE
> Task :gradle-plugin:shared:classes UP-TO-DATE
> Task :gradle-plugin:shared:jar UP-TO-DATE
> Task :gradle-plugin:settings-plugin:compileKotlin UP-TO-DATE
> Task :gradle-plugin:settings-plugin:compileJava NO-SOURCE
> Task :gradle-plugin:settings-plugin:pluginDescriptors UP-TO-DATE
> Task :gradle-plugin:settings-plugin:processResources UP-TO-DATE
> Task :gradle-plugin:settings-plugin:classes UP-TO-DATE
> Task :gradle-plugin:settings-plugin:jar UP-TO-DATE
> Task :gradle-plugin:react-native-gradle-plugin:checkKotlinGradlePluginConfigurationErrors
> Task :gradle-plugin:react-native-gradle-plugin:compileKotlin UP-TO-DATE
> Task :gradle-plugin:react-native-gradle-plugin:compileJava NO-SOURCE
> Task :gradle-plugin:react-native-gradle-plugin:pluginDescriptors UP-TO-DATE
> Task :gradle-plugin:react-native-gradle-plugin:processResources UP-TO-DATE
> Task :gradle-plugin:react-native-gradle-plugin:classes UP-TO-DATE
> Task :gradle-plugin:react-native-gradle-plugin:jar UP-TO-DATE
> Task :app:checkKotlinGradlePluginConfigurationErrors
> Task :app:generateAutolinkingNewArchitectureFiles UP-TO-DATE
> Task :app:generateAutolinkingPackageList UP-TO-DATE
> Task :app:generateCodegenSchemaFromJavaScript UP-TO-DATE
> Task :app:generateCodegenArtifactsFromSchema UP-TO-DATE
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:checkDebugAarMetadata UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:mapDebugSourceSetPaths UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:packageDebugResources UP-TO-DATE
> Task :app:parseDebugLocalResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugMainManifest UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugManifestForPackage UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE
> Task :app:compileDebugKotlin UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:compileDebugJavaWithJavac UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:compressDebugAssets UP-TO-DATE
> Task :app:desugarDebugFileDependencies UP-TO-DATE
> Task :app:dexBuilderDebug UP-TO-DATE
> Task :app:mergeDebugGlobalSynthetics UP-TO-DATE
> Task :app:processDebugJavaRes UP-TO-DATE
> Task :app:mergeDebugJavaResource UP-TO-DATE
> Task :app:checkDebugDuplicateClasses UP-TO-DATE
> Task :app:mergeExtDexDebug UP-TO-DATE
> Task :app:mergeLibDexDebug UP-TO-DATE
> Task :app:mergeProjectDexDebug UP-TO-DATE
> Task :app:configureCMakeDebug[arm64-v8a]
> Task :app:buildCMakeDebug[arm64-v8a]
> Task :app:configureCMakeDebug[armeabi-v7a]
> Task :app:buildCMakeDebug[armeabi-v7a]
> Task :app:configureCMakeDebug[x86]
> Task :app:buildCMakeDebug[x86]
> Task :app:configureCMakeDebug[x86_64]
> Task :app:buildCMakeDebug[x86_64]
> Task :app:mergeDebugJniLibFolders UP-TO-DATE
> Task :app:mergeDebugNativeLibs UP-TO-DATE
> Task :app:stripDebugDebugSymbols UP-TO-DATE
> Task :app:validateSigningDebug UP-TO-DATE
> Task :app:writeDebugAppMetadata UP-TO-DATE
> Task :app:writeDebugSigningConfigVersions UP-TO-DATE
> Task :app:packageDebug UP-TO-DATE
> Task :app:createDebugApkListingFileRedirect UP-TO-DATE

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'RMX3771 - 14' for :app:debug
Installed on 1 device.

BUILD SUCCESSFUL in 25s
64 actionable tasks: 13 executed, 51 up-to-date
info Connecting to the development server...
info Starting the app on "5XAIKRCAZX9XBEEY"...
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.turbomoduleexample/.MainActivity }
 BUNDLE  ./index.js

Let me know if you need something else, since the bug is in developement so i provided the build logs for debug build.

cortinico commented 2 weeks ago

Just tested your reproducer and it works fine on my machine:

https://github.com/user-attachments/assets/bdb19b0c-1c36-423f-948f-b62e8519c071

Do you happen to have any spaces in the full path of your project (like in any of the parent folders also)?

CodeWithBlaze commented 2 weeks ago

No there is no space in the full path of my project. Also I would request you to test it on android 14 the video shows API 32 which is Android 12 so can you please try on android 14. Also this is happening in windows for me, i am not sure of mac

cortinico commented 2 weeks ago

Also I would request you to test it on android 14 the video shows API 32 which is Android 12 so can you please try on android 14

Same, cannot reproduce:

https://github.com/user-attachments/assets/edc40760-4ccd-448b-a1e8-512f7d59687b

CodeWithBlaze commented 2 weeks ago

i guess then it is a windows specific issue because i tried it on three diff project and same happened for all of them. I will test it on a diff system and will update you soon. if the error persist then we can keep this open or else it will my my device specific problem so will close this issue then.

CodeWithBlaze commented 2 weeks ago

Hey @cortinico i have tested it in a seperate windows device (installed everything from scratch even the SDK) and the issue is still there. I do not have a mac to test on but it seems the error is popping up in windows system.

CodeWithBlaze commented 2 weeks ago

can anyone verify this by testing a brand new app on a windows machine. I have already tested it in 2 device. @cortinico is it possible for you to test in a windows environment ?

cavadibrahimli1 commented 2 weeks ago

@CodeWithBlaze I tested same on Windows, and I have same issue.

cavadibrahimli1 commented 2 weeks ago

image

@cortinico What do you think? How can this issue could be mitigated?

CodeWithBlaze commented 2 weeks ago

@cavadibrahimli1 just wanted to know did you create your own native turbo module or this happened when you installed something

cavadibrahimli1 commented 2 weeks ago

@CodeWithBlaze I just follow the tutorial on the React's official website below:

Tutorial

I did everything related to android side. It finished its build successfully. What about you?

CodeWithBlaze commented 2 weeks ago

@cavadibrahimli1 I followed this exactly Tutorial

cavadibrahimli1 commented 2 weeks ago

My main goal is just running one cpp code in my app. But I think, this issue is all about a bug @CodeWithBlaze

migueldaipre commented 2 weeks ago

Hey @CodeWithBlaze,

Can you show me the full path of your project and if it has any whitespaces?

CodeWithBlaze commented 2 weeks ago

@migueldaipre This is the fullpath to my project D:\poc\TurboModuleExample

cortinico commented 2 weeks ago

can anyone verify this by testing a brand new app on a windows machine. I have already tested it in 2 device.

I also tested it on a Windows machine and I cannot reproduce:

https://github.com/user-attachments/assets/f45a47f9-0561-4b01-ab17-1de4a12b014c

CodeWithBlaze commented 2 weeks ago

@cortinico thank you so much for testing it on windows. I will do a test using yarn and powershell from my side. Like I have no clue why is it not working on my system. But appreciate your help

cavadibrahimli1 commented 2 weeks ago

@CodeWithBlaze can you share info about after testing it via yarn and on powershell

CodeWithBlaze commented 2 weeks ago

I am outside of my home for 2 days so need some time before I can provide you the info. Sorry for the inconvenience

cavadibrahimli1 commented 2 weeks ago

@CodeWithBlaze can you just mention me, when you solved or tried this?

CodeWithBlaze commented 2 weeks ago

@cavadibrahimli1 I didn't solved it yet neither tried with yarn and powershell. I am out of home, once I reach home then I will try and update here.

cavadibrahimli1 commented 2 weeks ago

@CodeWithBlaze I tried with yarn install - yarn start . It gave the same ERROR output

CodeWithBlaze commented 2 weeks ago

@cavadibrahimli1 I am not sure man why this is happening. Like personally yarn and npm both are package managers and powershell and cmd both are terminals so logically testing on them for diff result doesn't make sense at all but this is currently the best shot I got.

CodeWithBlaze commented 2 weeks ago

Hey Guys, i tested it using yarn and powershell and it worked. What i did is here

1) I deleted the node_modules 2) then i installed yarn using npm install --global yarn 3) then i tried yarn install in the project (in powershell) and i got this error

yarn : File C:\Users\sagni\AppData\Roaming\npm\yarn.ps1 cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yarn install
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

4) I solved it by finding this Solution 5) then simply yarn install 6) cd android 7) ./gradlew generateCodegenArtifactsFromSchema 8) cd .. 9) yarn android it worked. what i think is that npm failed to link the new lib whereas yarn did it properly. Not sure why this worked but just guessing and hope that it works for all of you.

Thank you @cortinico for helping out so much in this issue. Let me know if i can help you out in any way (although i don't know much android)

cavadibrahimli1 commented 2 weeks ago
  • then i installed yarn using npm install --global yarn

Sir, did you use npm install -global yarn command in the root directory of your project?

CodeWithBlaze commented 2 weeks ago

@cavadibrahimli1 Bro firstly no sir, friend or bro works 😁. Second dosen't matter where you run this command as yarn will be installed globally and will be available in all projects. But just to answer your question yes, I ran it in my project directory using cmd in administrator mode.

cavadibrahimli1 commented 2 weeks ago

I did the same thing you mentioned. @CodeWithBlaze , but it didn't worked for me

cavadibrahimli1 commented 2 weeks ago

image

The error I got is

CodeWithBlaze commented 2 weeks ago

@cavadibrahimli1 I think your problem is diff than mine and mostly related to this Issue. Please check this out once. Let me know the result so that I can decide on whether to close this issue or not. Most probably it is due to the case that you are passing your own CMake file overriding the original

CodeWithBlaze commented 2 weeks ago

@cortinico or @migueldaipre can you please tell me how to add multiple turbo modules in the codegen config in package.json. This is not mention in the docs ?

yzj2019 commented 4 days ago

我也是类似的解决方法:

bartlian commented 4 days ago

I have used yarn to re

我也是类似的解决方法:

  • win11 下使用 npx react-native run-android 编译了 react native template,之后编写了 turbo 模块后 使用 yarn react-native run-android 进行编译,会报错查询不到 turbo module;
  • 执行 yarn react-native clean ,选择 android build cache,之后再使用 yarn react-native run-android 进行编译就可以查询到 turbo 模块了

I have used yarn to re-install node_modules and run , then it worded,

CodeWithBlaze commented 4 days ago

Here is my understanding on this and following this should solve it for all cases

  1. The docs are misleading Turbo Module docs You can have one or muliple Turbo Modules but there will only one codegen config for all of them
  2. Understanding codegen config: Codegen scans all the files in the specified folder jsSrcsDir with any files whose name starts with "Native".
  3. "android": { "javaPackageName": "com.anynameyouwant" } this line specifies the codegen output package for all of your turbo modules. basically the specs it has generated will be stored here

    1. I am still confused that whether we have to create module(taking about java module)(in docs NativeLocalStorageModule.java) for each of the turbo module or a single file for all of them. So currently i can confirm that for each turbo module if you create one module file it will work.
    2. Same goes for package(java package, in docs NativeLocalStoragePackage.java). not sure to create a single file or multiple file but mutliple file works (one for each turbo module)
    3. Finally add all your packages in the MainApplication.java like this packages.add(new FirstPackage()); package.add(new SecondPackage()); and so on (FirstPackage and SecondPackage names are just for ref. Replace them with your own package name)

    I hope it helps Also if anyone can confirm point 4 and point 5 that will be great. thnx

yzj2019 commented 4 days ago

我可以补充一点:

cloud2303 commented 3 days ago

i found that enforcing I've encountered a strange issue. I wrote a C++ turbo module and created a lib. It worked perfectly when I used the function

export default TurboModuleRegistry.getEnforcing<Spec>('NativeCrypto'); 

in version 0.76.1.

However, after upgrading to versions 0.76.2 and 0.76.3, and after excluding the issue with the Windows packaging CMake path, using getEnforcing gives the error: EarlyJsError: TurboModuleRegistry.getEnforcing(...) [module name] could not be found. Verify that a module by this name is registered in the native binary. Interestingly, when I change the export of the problematic NativeCrypto module to get, it works fine again. This is very strange.