[Bug] init-windows adds incorrect name of Native Codegen File Include
Problem Description
Run init-windows new arch template command
Steps To Reproduce
Clone react-native-webview Run init-windows new arch template command Check the .h boiler code and included native codegen file name
Expected Results
For example in webview .h file, it adds below
#include "codegen/NativeReactNativeWebviewSpec.g.h"
instead the expectation was below
#include "codegen/NativeRNCWebviewModuleSpec.g.h"
Workaround is to manually rename and fix it but ideally the script should support correct naming of include files
Fix init-windows new arch command in codegen that when it creates the boiler .h file it should include the correct nativemodulespec.g.h file name check from path
CLI version
17.0.0
Environment
info Fetching system and libraries information...
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
Memory: 26.71 GB / 63.95 GB
Binaries:
Node:
version: 22.14.0
path: C:\nvm4w\nodejs\node.EXE
Yarn:
version: 1.22.22
path: C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm:
version: 10.9.2
path: C:\nvm4w\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
AllowAllTrustedApps: Enabled
Versions:
- 10.0.17763.0
- 10.0.19041.0
- 10.0.22621.0
- 10.0.26100.0
IDEs:
Android Studio: Not Found
Visual Studio:
- 17.14.36408.4 (Visual Studio Enterprise 2022)
- 17.14.36408.4 (Visual Studio Community 2022)
Languages:
Java: Not Found
Ruby: Not Found
npmPackages:
"@react-native-community/cli": Not Found
react: Not Found
react-native: Not Found
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Community Modules
react-native-webview
Target React Native Architecture
None
Target Platform Version
None
Visual Studio Version
None
Build Configuration
None
Snack, code example, screenshot, or link to a repository
No response
I ran into the same issue. When I created a Native Module using
yarn dlx [email protected] --react-native-version "0.80.0" music-player,
the folder name was music-player, but the name field in package.json was react-native-music-player (because that’s how create-react-native-library sets it by default).
Then, running
yarn workspace react-native-music-player dlx react-native init-windows --template cpp-lib --overwrite
generated NativeMusicPlayerSpec.g.h under the codegen directory.
However, ReactNativeMusicPlayer.h includes
#include "codegen/NativeReactNativeMusicPlayerSpec.g.h",
so the build failed.
I tried yarn dlx [email protected] --react-native-version "0.80.0" react-native-media-player. But the codegen still miss the ReactNative.
I ran into the same issue. When I created a Native Module using
yarn dlx [email protected] --react-native-version "0.80.0" music-player, the folder name wasmusic-player, but thenamefield inpackage.jsonwasreact-native-music-player(because that’s howcreate-react-native-librarysets it by default).Then, running
yarn workspace react-native-music-player dlx react-native init-windows --template cpp-lib --overwritegeneratedNativeMusicPlayerSpec.g.hunder thecodegendirectory.However,
ReactNativeMusicPlayer.hincludes#include "codegen/NativeReactNativeMusicPlayerSpec.g.h", so the build failed.I tried
yarn dlx [email protected] --react-native-version "0.80.0" react-native-media-player. But the codegen still miss theReactNative.
Yeah looks like the PR is ready.. will fix it soon
This issue is that the template is using the project name instead of the value specified in the project's package.json under codegenConfig, i.e.:
"codegenConfig": {
"name": "RNCWebViewSpec", /// <-- We should be using this value, not calculating it by reading from disk
"type": "all",
"jsSrcsDir": "./src",
"android": {
"javaPackageName": "com.reactnativecommunity.webview"
},
The fix implemented in PR #15094 may come up with the same answer sometimes, but it should fail when running the init-windows command for the first time because the codegen files won't exist until after the command has finished and theuser then runs either codegen-windows or run-windows first.
Furthermore, the there may be multiple spec files in that folder folder (a library can have more than one native module, and so have multiple spec files) and injecting all of them into the same REACT_MODULE struct forces developers to implement all of their native module APIs in that one struct (and will break if two different modules have matching API signatures).