question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error setting up in iOS (lib/dist/index.js doesn't exist)

See original GitHub issue

The 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 filewhatever, the package /project/ios/Pods/react-native-notifications/package.jsonwas successfully found. However, this package itself specifies amain 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
JulioCcommented, May 5, 2020

Metro Bundler has encountered an error: While trying to resolve module react-native-notificationsfrom filewhatever, the package /project/ios/Pods/react-native-notifications/package.json was successfully found. However, this package itself specifies amain module field that could not be resolved (/project/ios/Pods/react-native-notifications/lib/dist/index.js. Indeed, none of these files exist

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 under node_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:

diff --git a/node_modules/react-native-notifications/react-native-notifications.podspec b/node_modules/react-native-notifications/react-native-notifications.podspec
index c8e4e78..6db6a69 100644
--- a/node_modules/react-native-notifications/react-native-notifications.podspec
+++ b/node_modules/react-native-notifications/react-native-notifications.podspec
@@ -3,7 +3,7 @@ require 'json'
 package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
 
 Pod::Spec.new do |s|
-  s.name           = 'react-native-notifications'
+  s.name           = 'ReactNativeNotifications'
   s.version        = package['version']
   s.summary        = package['description']
   s.description    = package['description']
@@ -15,7 +15,7 @@ Pod::Spec.new do |s|
   s.requires_arc   = true
   s.platform       = :ios, '8.0'
 
-  s.preserve_paths = 'LICENSE', 'README.md', 'package.json', 'notification.ios.js', 'notification.android.js', 'index.android.js', 'index.ios.js'
+  s.preserve_paths = 'LICENSE', 'README.md', 'notification.ios.js', 'notification.android.js', 'index.android.js', 'index.ios.js'
   s.source_files   = 'lib/ios/*.{h,m}'
 
   s.dependency 'React'

Change ios/Podfile entry to:

  pod 'ReactNativeNotifications', :podspec => '../node_modules/react-native-notifications/react-native-notifications.podspec'
  • Run yarn install and cd ios && pod install
2reactions
mkizesovcommented, Feb 26, 2021

@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 run npm 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 adding files to package.json – it’s not needed for this lib)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to Resolve Module in React Native App - Stack Overflow
js file I import {AppContainer} from '~/containers . When I try ./containers I get another error saying another directory doesn't exist ...
Read more >
Firebase JavaScript SDK Release Notes - Google
Updated "missing index" error message to include the link to create the composite index. See Github issue #6613. Updated transaction.set() failure to now...
Read more >
Handling common JavaScript problems - MDN Web Docs
Now we'll look at common cross-browser JavaScript problems and how to fix them. This includes information on using browser dev tools to track ......
Read more >
Integration with Existing Apps - React Native
The specific steps are different depending on what platform you're targeting. Android (Kotlin); Android (Java); iOS (Objective-C) ...
Read more >
Troubleshooting build errors and crashes - Expo Documentation
If you are working on a managed app and the build error is a native error rather than a JavaScript error, this is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found