`react-native bundle --platform wpf ...` doesn't work
Environment
-
react-native -v: react-native-cli: 2.0.1 react-native: 0.55.3 -
npm ls rnpm-plugin-windows: [email protected] `-- [email protected] -
npm ls react-native-windows: [email protected] `-- [email protected] (I also confirmed the same issues on react-native 0.54.4 & react-native-windows 0.54.) -
node -v: v9.11.1 -
npm -v: 5.6.0 -
yarn --version: 1.6.0
Then, specify:
- Target Platform: WPF
- Target Platform Version(s): .NET 4.6
- Target Device(s): Desktop (Win 10)
- Development Operating System: Windows
- Visual Studio Version: Visual Studio 2017
Steps to Reproduce
react-native init react_native_windows_failed_build_wpf --version=0.55.3yarn add rnpm-plugin-windows --devreact-native windows- Confirm a UWP app works via
react-native run-windows - Confirm we can build a UWP app via
react-native bundle --platform windows --entry-file index.js --bundle-output windows\react_native_windows_failed_build_wpf\ReactAssets\index.windows.bundle --assets-dest windows\react_native_windows_failed_build_wpf\ReactAssets react-native wpf- Confirm a WPF app DOES NOT work via
react-native run-wpf - Open and compile
wpf\react_native_windows_failed_build_wpf.slnwith VS 2017 to fix compile errors. - Confirm a WPF app works via
react-native run-wpf - Confirm we CANNOT build a WPF app via
react-native bundle --platform wpf --entry-file index.js --bundle-output wpf\react_native_windows_failed_build_wpf\ReactAssets\index.wpf.bundle --assets-dest wpf\react_native_windows_failed_build_wpf\ReactAssets
Expected Behavior
- No error is shown when doing
react-native bundle --platform wpf react-native run-wpfworks well without opening and compiling theslnfile with VS 2017.
Actual Behavior
- The following errors are shown when doing
react-native bundle --platform wpf:
Scanning folders for symlinks in C:\Users\exKAZUu\Projects\react_native_windows_failed_build_wpf\node_modules (36ms)
Scanning folders for symlinks in C:\Users\exKAZUu\Projects\react_native_windows_failed_build_wpf\node_modules (40ms)
Loading dependency graph, done.
Unable to resolve module `AccessibilityInfo` from `C:\Users\exKAZUu\Projects\react_native_windows_failed_build_wpf\node_modules\react-native\Libraries\react-native\react-native-implementation.js`: Module `AccessibilityInfo` does not exist in the Haste module map
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
react-native run-wpfdoesn't work well without opening and compiling theslnfile with VS 2017.
Reproducible Demo
https://github.com/exKAZUu/react_native_windows_failed_build_wpf.git
I think the reason why this error occurs is that there is NO AccessibilityInfoModule.cs in ReactNative.Net46 project for WPF (though there is AccessibilityInfoModule.cs in ReactNative project for UPW).
Okay, I found the cause of this error.
https://github.com/Microsoft/react-native-windows/tree/master/Libraries includes only XXX.windows.js (no XXX.wpf.js)!
I feel this status is really wired.
@reseul Is this intended? If no, I will start implementing XXX.wpf.js files in Libraries. But, this task requires a lot of efforts. I need some help...
@exKAZUu I don't know what XXX.wpf.js is. "windows" files should cover both UWP and WPF. But maybe I don't understand the question.
@reseul (c.c. @rozele) Thank you for your quick response. I'm sorry about my unclear question.
react-native bundle --platform wpf ... seems to read only XXX.wpf.js in Libraries directory and then it complains that there is no XXX.
My question was, did the comitters intentionally avoid creating XXX.wpf.js? So, I understand your answer is yes.
Did react-native bundle --platform wpf ... work well previously? Is this error caused by one of the specification changes in react-native bundle?
By the way, let me explain my idea about this issue. I think there are two problems and we should implement XXX.wpf.js in addition to XXX.windows.js to resolve these problems.
- Currently,
react-native bundle --platform wpf ...reads onlyXXX.wpf.jsignoringXXX.windows.js. ReactNative.Net46project doesn't have some native modules whichReactNativeproject has (e.g.AccessibilityInfo). (Though this is not directly related to the error I reported.)
Problem 1
I recognized that adding XXX.wpf.js in Libraries directory removes this error as follows.
- Create a WPF project.
- Do
react-native bundle --platform wpf ...but this command fails showing the following error.
Unable to resolve module `AccessibilityInfo` from `C:\Users\exKAZUu\Projects\react_native_windows_failed_build_wpf\node_modules\react-native\Libraries\react-native\react-native-implementation.js`: Module `AccessibilityInfo` does not exist in the Haste module map
- Create
AccessibilityInfo.wpf.jsby copyingAccessibilityInfo.windows.js. - Do
react-native bundle --platform wpf ...but this command fails showing the following error.
Unable to resolve module `CheckBox` from `C:\Users\exKAZUu\Projects\react_native_windows_failed_build_wpf\node_modules\react-native\Libraries\react-native\react-native-implementation.js`: Module `CheckBox` does not exist in the Haste module map
- Create
CheckBox.wpf.jsby copyingCheckBox.windows.js. - Do
react-native bundle --platform wpf ...but this command fails showing another similar error. - Repeat 5-6
Problem 2
Even if AccessibilityInfo.windows.js is used in a WPF project, ReactNative.Net46 has no AccessibilityInfo module, so the js file should report that this is unimplemented in WPF.
Solution for Both Problems
We should seprately implement XXX.wpf.js in addition to XXX.windows.js.
Is this solution okay for you? If so, I will try making a PR.
@reseul (c.c. @rozele) Sorry, my idea was probably wrong ... I can avoid this issue with the following command on Git Bash. To avoid errors, I must copy specific XXX.windows.js files to XXX.wpf.js files. I cannot understand the reason ...
for path in `find ./node_modules/react-native-windows/Libraries/ -name "*.windows.js"`; do
cp $path ${path/.windows./.wpf.}
done
rm ./node_modules/react-native-windows/Libraries/Alert/Alert.wpf.js
rm ./node_modules/react-native-windows/Libraries/Network/NetInfo.wpf.js
rm ./node_modules/react-native-windows/Libraries/ReactNative/UIManager.wpf.js
rm ./node_modules/react-native-windows/Libraries/Core/ReactNativeVersion.wpf.js
rm ./node_modules/react-native-windows/Libraries/ReactNative/requireNativeComponent.wpf.js
rm ./node_modules/react-native-windows/Libraries/Vibration/Vibration.wpf.js
rm ./node_modules/react-native-windows/Libraries/WebSocket/WebSocket.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/ActivityIndicator/ActivityIndicator.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/AppleTV/TVEventHandler.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/Picker/Picker.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/ScrollView/ScrollView.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/StatusBar/StatusBar.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/TextInput/TextInputState.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/TextInput/TextInput.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/View/PlatformViewPropTypes.wpf.js
rm ./node_modules/react-native-windows/Libraries/Experimental/SwipeableRow/SwipeableRow.wpf.js
rm ./node_modules/react-native-windows/Libraries/Components/Button.wpf.js
Then both bundle commands work without any error.
react-native bundle --platform windows --entry-file index.js --bundle-output windows\react_native_windows_failed_build_wpf\ReactAssets\index.windows.bundle --assets-dest windows\react_native_windows_failed_build_wpf\ReactAssets
react-native bundle --platform wpf --entry-file index.js --bundle-output wpf\react_native_windows_failed_build_wpf\ReactAssets\index.wpf.bundle --assets-dest wpf\react_native_windows_failed_build_wpf\ReactAssets
@exKAZUu - this issue is related to a missing feature in metro. We have been requesting for a long time to have a feature in metro that allows us to "cascade" platforms. E.g., allow overrides of *.windows.js files with *.wpf.js or *.uwp.js files.
So, unfortunately, we are limited to only a single platform moniker for this repo unless we want to maintain two copies of every JavaScript file (which is not desireable). We need to introduce some additional constants from the DeviceInfoModule that gives details about the operating system version so we can at least include conditional logic in the *.windows.js files.
Here is the issue from metro: https://github.com/facebook/metro/issues/135
Thank you for sharing the information! I see.
@exKAZUu Any solution for this issue? I am also facing same issue and unable to create Release version of RN WPF app.
@exKAZUu I followed steps which you suggested above and it worked. Now I need to deploy RN WPF app. Do you know steps how to proceed? Would helpful if you can suggest.
In order to create bundle for WPF platform use 'windows' option instead of 'wpf':
react-native bundle --platform windows --entry-file index.js --bundle-output wpf\samplewpfapp\ReactAssets\index.wpf.bundle --assets-dest wpf\samplewpfapp\ReactAssets
Closing this issue, as react-native bundle --platform wpf … is not expected to work. See other comments for correct command.