Error setting up in iOS (lib/dist/index.js doesn't exist)
See original GitHub issueThe library works perfectly on Android, but in iOS when add the line:
pod 'react-native-notifications', :podspec => '../node_modules/react-native-notifications/react-native-notifications.podspec'
on the Podfile, install it and run the app, it crash because is unable to find the file lib/dist/index.js
See the full error:
Metro Bundler has encountered an error: While trying to resolve module
react-native-notificationsfrom file
whatever, the package
/project/ios/Pods/react-native-notifications/package.jsonwas successfully found. However, this package itself specifies a
main module field that could not be resolved (
/project/ios/Pods/react-native-notifications/lib/dist/index.js. Indeed, none of these files exist
The version is installing is: Installing react-native-notifications (3.1.4)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:19 (1 by maintainers)
The reason this happens is because the .podspec file includes package.json file, so it gets copied into
ios/Pods/react-native-notification
. React-native Metro bundler finds that package.json file and uses it instead of the proper file (which is still undernode_modules
).The solution for this specific problem is to delte the file
ios/Pods/react-native-notifications/package.json
.This will raise another issue: the js code is looking for a dependency called ReactNativeNotifications, but the .podspec registers the package as react-native-notifications. The easier way is to change the podspec file to match the native module. I’m not sure about the implications of doing that when autolinking though.
If possible, the library could ship two podspecs: the current one for auto-linking; and an alternative for manual link with the native name ReactNativeNotifications.podspec
Workaround while the library is not fixed:
Use patch-package to change the podspec file in node_module so it doesn’t include package.json in the pod and also register the proper name.
After installing patch-package and adding it as postinstall, save this as patch file in
patches/react-native-notifications+3.1.4.patch
:Change
ios/Podfile
entry to:yarn install
andcd ios && pod install
@madandrija If you use a fork, you can build a dist folder using
npm run build
. Then just add ‘dist’ folder to your repo and regenerate it after each js/ts code update. Or you can runnpm pack
in the react-native-notifications folder. It will generates a tgz file which you can upload as a binary to release in your github repo. More here https://glebbahmutov.com/blog/npm-install-with-just-github/ (just skip the part with addingfiles
to package.json – it’s not needed for this lib)