react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

`react-native bundle --platform wpf ...` doesn't work

Open exKAZUu opened this issue 8 years ago • 13 comments

Environment

  1. react-native -v: react-native-cli: 2.0.1 react-native: 0.55.3

  2. npm ls rnpm-plugin-windows: [email protected] `-- [email protected]

  3. 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.)

  4. node -v: v9.11.1

  5. npm -v: 5.6.0

  6. 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

  1. react-native init react_native_windows_failed_build_wpf --version=0.55.3
  2. yarn add rnpm-plugin-windows --dev
  3. react-native windows
  4. Confirm a UWP app works via react-native run-windows
  5. 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
  6. react-native wpf
  7. Confirm a WPF app DOES NOT work via react-native run-wpf
  8. Open and compile wpf\react_native_windows_failed_build_wpf.sln with VS 2017 to fix compile errors.
  9. Confirm a WPF app works via react-native run-wpf
  10. 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-wpf works well without opening and compiling the sln file 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-wpf doesn't work well without opening and compiling the sln file with VS 2017.

Reproducible Demo

https://github.com/exKAZUu/react_native_windows_failed_build_wpf.git

exKAZUu avatar Apr 23 '18 08:04 exKAZUu

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).

exKAZUu avatar Apr 26 '18 00:04 exKAZUu

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 avatar May 07 '18 16:05 exKAZUu

@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 avatar May 07 '18 17:05 reseul

@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.

  1. Currently, react-native bundle --platform wpf ... reads only XXX.wpf.js ignoring XXX.windows.js.
  2. ReactNative.Net46 project doesn't have some native modules which ReactNative project 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.

  1. Create a WPF project.
  2. 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
  1. Create AccessibilityInfo.wpf.js by copying AccessibilityInfo.windows.js.
  2. 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
  1. Create CheckBox.wpf.js by copying CheckBox.windows.js.
  2. Do react-native bundle --platform wpf ... but this command fails showing another similar error.
  3. 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.

exKAZUu avatar May 08 '18 00:05 exKAZUu

@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 avatar May 10 '18 15:05 exKAZUu

@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.

rozele avatar May 18 '18 14:05 rozele

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.

rozele avatar May 18 '18 14:05 rozele

Here is the issue from metro: https://github.com/facebook/metro/issues/135

rozele avatar May 18 '18 14:05 rozele

Thank you for sharing the information! I see.

exKAZUu avatar May 21 '18 02:05 exKAZUu

@exKAZUu Any solution for this issue? I am also facing same issue and unable to create Release version of RN WPF app.

piyush965 avatar May 21 '18 06:05 piyush965

@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.

piyush965 avatar May 21 '18 12:05 piyush965

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

praveen4zenith avatar Jun 05 '18 09:06 praveen4zenith

Closing this issue, as react-native bundle --platform wpf … is not expected to work. See other comments for correct command.

rozele avatar Jun 05 '18 13:06 rozele