Newly create local module does not exist in Haste module map
See original GitHub issueš Bug Report
Iām trying to import a module I created in my App.js file
import RNModule from 'react-native-module';
The module is not found by metro when trying to load the project.
Yes I have tried:
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-*`.
It however works if you import the module using NativeModules
ā¦
import { NativeModules } from 'react-native';
const { RNModule } = NativeModules;
To Reproduce
- Create project using
react-native init
- Create a library using
react-native-create-library
- npm install your library from your project
- react-native link <your library>
- import the library in the App.js (or anywhere else) of the project
- Try run
react-native run-android
orreact-native run-ios
Expected Behavior
The project should load without issues.
Code Example
https://github.com/814k31/TestReactNativeNativeModule
Environment
React Native Environment Info: System: OS: macOS 10.14.2 CPU: (8) x64 IntelĀ® Coreā¢ i7-6700K CPU @ 4.00GHz Memory: 486.52 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.13.0 - /usr/local/bin/node npm: 6.4.1 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 Android SDK: API Levels: 22, 23, 26, 27, 28 Build Tools: 23.0.1, 25.0.0, 26.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3 System Images: android-28 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.2 AI-181.5540.7.32.5014246 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: react: 16.6.3 => 16.6.3 react-native: ^0.58.3 => 0.58.3 npmGlobalPackages: create-react-native-app: 2.0.2 react-native-ci-tools: 1.1.0 react-native-cli: 2.0.1 react-native-create-library: 3.1.2 react-native-git-upgrade: 0.2.7
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top GitHub Comments
@814k31 Several options, but the ones I like to use is to checkout the library inside the node_modules or when Iām working on a library and an app project in parallel I use https://github.com/wix/wml
Neither solution is perfect but it gets the job done. Hope this helps you along.
@814k31 Thank you for the solid repro repository! Iāve checked out the project and I donāt have any issues importing the library. Are you sure you are not symlinking the library into node_modules? Because that doesnāt work with the metro bundler https://github.com/facebook/metro/issues/1.
These are the commands that lead to the below screenshot: