bundling failed: Error: Unable to resolve module `warnOnce` when referring an another RN module
Environment
-
react-native -v: react-native: 0.60.6 -
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
- Create a react-native module called "module1" and a component called "Welcome" and render a RN Text
- Create RN app called "SimpleApp"
- 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
- 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:
- Clear watchman watches:
watchman watch-del-all. - Delete the
node_modulesfolder:rm -rf node_modules && npm install. - Reset Metro Bundler cache:
rm -rf /tmp/metro-bundler-cache-*ornpm start -- --reset-cache. - 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'), ],
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.
- #3611 You are using node 12, and most likely you are hitting this. Please use node 10.
- #3670 It's easy for you to verify it with
cmd /K cd /d, please refer to the bug description for more details.
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.
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.
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.
For reference: https://github.com/facebook/metro/issues/1
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.