react-nativeexpofirebase-cloud-messagingonesignalreact-native-onesignal

Onesignal Expo SDK Setup Google Android FCM Configuration, cannot read property 'smallIcons' of undefined at withSmallIcons (\withOneSignalAndroid.js)


I'm using Onesignal for push notifications but am stuck in an error and could not find the solution for many days.

OneSignal SDK Configuration:

  1. I configured the Google Android (FCM) Configuration with Firebase Server Key and Firebase Sender ID at Onesignal and selected the React Native/Expo SDK and copied the APP ID.

Expo SDK Setup:

  1. I have Expo Managed Workflow so I run the command

expo install onesignal-expo-plugin

  1. then I executed the command

yarn add react-native-onesignal

  1. Added the below code into App.json

{ "plugins": [ "onesignal-expo-plugin", { "mode": "development", }] }

  1. After that import react-native-onesignal and used APP ID in useEffect into reuqired JS

import OneSignal from 'react-native-onesignal';

useEffect(() => { OneSignal.setAppId("Pasted Copied APP ID here"); }, []);

  1. After that Run the Command

expo prebuild

but getting error

TypeError: Cannot read property 'smallIcons' of undefinedn at withSmallIcons (\node_modules\onesignal-expo-plugin\build\onesignal\withOneSignalAndroid.js)

now getting this error on all console commands related to this react-native project.

I configured Onesignal through the below documentation https://documentation.onesignal.com/docs/react-native-expo-sdk-setup


Solution

  • I solved it. actually, the error was occurring in the below code

    "plugins": [
            "onesignal-expo-plugin",
            {
              "mode": "development"
            }
        ]
    

    adding the extra Square brackets [ ] solved the "Cannot read property 'smallIcons' of undefined" problem

    "plugins": [
          [
            "onesignal-expo-plugin",
            {
              "mode": "development"
            }
          ]
        ]