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

bundling failed: Error: Unable to resolve module `warnOnce` when referring an another RN module

Open rtselvan opened this issue 6 years ago • 6 comments

Environment

  1. react-native -v: react-native: 0.60.6

  2. react-native run-windows --info:

System: OS: Windows 10 10.0.18363 CPU: (12) x64 Intel(R) Xeon(R) W-2133 CPU @ 3.60GHz Memory: 18.53 GB / 31.66 GB Binaries: Node: 12.9.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.19.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.13.1 - C:\Program Files\nodejs\npm.CMD npmPackages: react: 16.8.6 => 16.8.6 react-native: ^0.60.0 => 0.60.6 react-native-windows: 0.60.0-vnext.86 => 0.60.0-vnext.86 rnpm-plugin-windows: ^0.3.8 => 0.3.8 Installed UWP SDKs: 10.0.14393.0 10.0.15063.0 10.0.16299.0 10.0.17106.0 10.0.17749.0 10.0.17763.0 10.0.18362.0

Steps to Reproduce

  1. Create a react-native module called "module1" and a component called "Welcome" and render a RN Text
  2. Create RN app called "SimpleApp"
  3. Add the module1 as dev-dependency in the package.json and refer and use the "module1" in app.tsx (SimpleApp) and render the module1 component i.e
  4. Run the SimpleApp and get the follow error on the UI and as well as metro log

Expected Behavior

Expected no errors and the app displays the module1 controls on the screen

Actual Behavior

error: bundling failed: Error: Unable to resolve module warnOnce from D:\dev\play\react-native\SimpleApp\node_modules\react-native\Libraries\react-native\react-native-implementation.js: Module warnOnce 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-*. at ModuleResolver.resolveDependency (D:\dev\play\react-native\SimpleApp\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:183:15) at ResolutionRequest.resolveDependency (D:\dev\play\react-native\SimpleApp\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18) at DependencyGraph.resolveDependency (D:\dev\play\react-native\SimpleApp\node_modules\metro\src\node-haste\DependencyGraph.js:283:16) at Object.resolve (D:\dev\play\react-native\SimpleApp\node_modules\metro\src\lib\transformHelpers.js:264:42) at D:\dev\play\react-native\SimpleApp\node_modules\metro\src\DeltaBundler\traverseDependencies.js:399:31 at Array.map () at resolveDependencies (D:\dev\play\react-native\SimpleApp\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:18) at D:\dev\play\react-native\SimpleApp\node_modules\metro\src\DeltaBundler\traverseDependencies.js:269:33 at Generator.next () at asyncGeneratorStep (D:\dev\play\react-native\SimpleApp\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)

Additional context

I was trying to React Link the module1 into the SimpleApp and it didn't work. So ended up adding a watch folder for the module1 in the metro.config.js

watchFolders: [ path.resolve(__dirname, '../module1'), ],

rtselvan avatar Dec 11 '19 01:12 rtselvan

We already know two bugs which may cause warnOnce, but we have no ETA for the fix yet(They have external dependencies). Please confirm if you are related to any of them or not.

  1. #3611 You are using node 12, and most likely you are hitting this. Please use node 10.
  2. #3670 It's easy for you to verify it with cmd /K cd /d , please refer to the bug description for more details.

licanhua avatar Dec 11 '19 17:12 licanhua

I had experienced the same issue yesterday. I tried different ways to approach it and in the end it was fixed. I am not sure what helped. Essentially I uninstalled Node.js and Yarn and then reinstalled the Node.js version 12.9.1 and latest Yarn. I also removed all caches. It started to work after that. But I bet there was an easier fix. Anyway, the issue seems to be related to the development machine state rather than the repo contents.

vmoroz avatar Dec 12 '19 01:12 vmoroz

Yeah, I have it working by manually clearing the cache and etc.

However the issue still happens when react-native link option is used for parallel development of the module and app.

rtselvan avatar Dec 13 '19 01:12 rtselvan

Is this a general issue with Metro and sym links? Does this work for you with Android/iOS? Lack of support for sym links in Metro is a known limitation.

chrisglein avatar Dec 13 '19 19:12 chrisglein

For reference: https://github.com/facebook/metro/issues/1

acoates-ms avatar Dec 13 '19 19:12 acoates-ms

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 14 days of this comment.

ghost avatar Dec 20 '19 20:12 ghost