OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.57k stars 374 forks source link

No such module 'OneSignal' #1370

Closed schoenbl closed 2 years ago

schoenbl commented 2 years ago

Description:

This is listed as a common issue: https://documentation.onesignal.com/docs/troubleshooting-ios

Resources that I have found have not been able to solve the issue. I've searched online and through the prior issues that people have listed on github.

In OneSignalNotificationServiceExtension, I receive the error: No such module 'OneSignal'

Screen Shot 2022-03-10 at 7 39 22 PM

Environment

I am running Xcode 13.2.

I installed through npm:

"react-native-onesignal": "^4.3.7",

This is my podfile:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'PodApp' do
  target 'OneSignalNotificationServiceExtension' do
    pod 'OneSignalXCFramework', '>= 3.0', '< 4.0'
  end
  ...
end

Steps to Reproduce Issue: I followed the React Native SDK Setup: https://documentation.onesignal.com/docs/react-native-sdk-setup

ekediala commented 2 years ago

Hi. Trust you are well. Did you find a solution to this? I have the same problem and I can't find a solution that works.

jesse-savary commented 2 years ago

Also running into this after weeks of running this lib without issue. The error fully blocked our build process and unfortunately I had to remove OneSignal entirely. Would greatly appreciate a fix.

Edit: things are working now but unfortunately I can't pinpoint what changed -- moving forward cautiously but concerned this bug will break things when moving into prod

schoenbl commented 2 years ago

I haven't found a solution. I've been sending message with their support, and they sent this:

When updating to the major release version of our SDK it does have some breaking changes.

We have step by step migration guides here that should explain the change https://documentation.onesignal.com/docs/mobile-2020-api-migration-guide

I tried what is in the documentation, but there may have been other issues wrong as well; they said that the target should not be added into the react native target, and instead be added by itself.

I moved on to using firebase, but I may try and see if some of the other feedback they gave works. It's pretty frustrating.

ekediala commented 2 years ago

I haven't found a solution. I've been sending message with their support, and they sent this:

When updating to the major release version of our SDK it does have some breaking changes.

We have step by step migration guides here that should explain the change https://documentation.onesignal.com/docs/mobile-2020-api-migration-guide

I tried what is in the documentation, but there may have been other issues wrong as well; they said that the target should not be added into the react native target, and instead be added by itself.

I moved on to using firebase, but I may try and see if some of the other feedback they gave works. It's pretty frustrating.

Thanks a lot. I removed all traces of OneSignal and redid the process in the documentation. It worked the second time.

carolvalenca commented 2 years ago

Same problem here, I followed the OneSignal documentation step by step but couldn't build my app yet!

jesse-savary commented 2 years ago

In my case this error appears to be related to my M1 Mac; I solved the issue by modifying my project.pbxproj:

change:

"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386";

to:

"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386";

Not a huge fan of this as AFAIK it forces my iOS simulator to use Rosetta when running my app but at least things are building.

JuanpaG94 commented 2 years ago

In my case the error was M1 Mac arm architecture too.

In addition to this, @jesse-savary's comment is correct and is in fact one of the necessary steps to achieve OneSignal (or another Pod with the same issue) to compile, but I needed to add a post_install script into Podfile which force every single Pod to target x86_64 architecture on compilation, and this config is not available via project.pbxproj file so this post_install script is crucial.

This additional last step was necessary for me in order to make my project to compile.

You simple need to add this to your Podfile:

target 'YourApp' do
  # ... all your dependencies etc.

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        # Force CocoaPods targets to always build for x86_64
        config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
      end
    end
  end

end

There's an alternative to EXCLUDED_ARCHS which is not excluding architectures BUT limiting 'Any iOS Simulator SDK' to just be x86_64 so you don't need to exclude archs by limiting them to the only compatible one. You can do this by adding this into project.pbxproj:

"ARCHS[sdk=iphonesimulator*]" = x86_64; (or configuring it via Xcode UI).

All this information was extracted from this blog post(which saved my life), and explains everything in a very clear and direct way: https://blog.sudeium.com/2021/06/18/build-for-x86-simulator-on-apple-silicon-macs/

Of course this will forcing Simulator to run with Rosetta but there's no alternative which works in the time I'm writting this. This solution applies to every arm Apple Silicon: M1, M1 Pro/Max/Ultra.

Happy coding! 🚀

rgomezp commented 2 years ago

Duplicate of https://github.com/OneSignal/react-native-onesignal/issues/1260

Ebeldev commented 2 years ago

@rgomezp I do not see how this is a duplicate of #1260 ?

People are talking about M1 chips.. I'm on Intel chips and I do have the same no such module error.

And in both issues. There is not a proper and clean response how to fix this.

It's been more then a year.

Ebeldev commented 2 years ago

I was able to get ride of the error.

What I did you may ask !! .

I use to open xcodeproj file but instead open xcworkspace file and it worked.

GSFZamai commented 2 years ago

I was able to get ride of the error.

What I did you may ask !! .

I use to open xcodeproj file but instead open xcworkspace file and it worked.

Worked for me too.

zdziczkowski commented 2 years ago

That's weird @Ebeldev and @GSFZamai ... everything we have learned says that is bad. Haha. Sadly, this did not work for me but I may be suffering from a separate issue.

Seamus1989 commented 1 year ago

on an M1 and I'm attempting to build an archive, I can build the app on my machine and run but cannot archive. All solutions including the above have failed.

milobob commented 1 year ago

after seeing Xcode give the No such module 'OneSignal' error, what worked for me is: 1) use terminal and run pod deintegrate and then pod install 2) use terminal to install npm install 2) use terminal and run react-native run-ios --device to load it onto my device 3) reload the project in xcode and all is well in the world 4) ... 5) profit

maybe xcode compiles differently than the react-native run-ios --device compilation method... not sure but it works now!

arys commented 1 year ago

if someone is facing this issue after installing watermelon db and have set use_frameworks option in podfile, try to install watermelon libs from static library.

  $static_framework = [ 
    'WatermelonDB',
    'simdjson',
  ]

  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if $static_framework.include?(pod.name)
        def pod.build_type;
          Pod::BuildType.static_library # >= 1.9
          # Pod::Target::BuildType.static_library #  pods version < 1.9
        end
      end
    end
  end

source https://github.com/Nozbe/WatermelonDB/issues/1285#issuecomment-1381323060

mathbalduino commented 1 year ago

Well, I'm having this issue, right now. Already tried a lot of different solutions, none worked. Does anyone else is experiencing this issue too?

sanny-naked commented 1 year ago

I encountered this issue yesterday when trying to build a target that was a duplicate of another one. This target was not present in our podfile. I created a shared config for the targets to use and the error went away.

def sharedConfig
   config goes here
end

def sharedOneSignal
   config goes here
end

target 'Target'
   sharedConfig
end

target 'Target Clone'
   sharedConfig
end

target 'OneSignalNotificationServiceExtension' do
   sharedOneSignal
 end

 target 'OneSignalNotificationServiceExtensionClone' do
   sharedOneSignal
 end
pdegnan commented 4 months ago

after seeing Xcode give the No such module 'OneSignal' error, what worked for me is:

  1. use terminal and run pod deintegrate and then pod install
  2. use terminal to install npm install
  3. use terminal and run react-native run-ios --device to load it onto my device
  4. reload the project in xcode and all is well in the world
  5. ...
  6. profit

maybe xcode compiles differently than the react-native run-ios --device compilation method... not sure but it works now!

this approach worked for me as well! 🤷‍♂️🙃

ZhenQian-keystone commented 2 months ago

If you're using React Native, please open the iOS folder directly in Xcode, and don't open the .xcodeproj file in the iOS folder but instead open the .xcworkspace file. As long as you've correctly run 'pod install' in React Native, you should be able to successfully resolve the 'no module' issue.

j-peace commented 2 days ago

It worked for me:

With OneSignal 5.0.0 (on Flutter) I had to use:

import OneSignalFramework

instead of

import OneSignal

https://stackoverflow.com/a/76936307/21819819