2

I'm trying to add the OneSignal SDK to my ReactNative project managed by Expo SDK, by following the guide here:

Expo One Signal

here is my plugin setup in App.js

    export default function App() {
  useEffect(() => {
   ///Other things
    OneSignal.setAppId(Constants.manifest.extra.oneSignalAppId);
  }, []);

unfortunately it doesn't work, first I was getting:

Invariant Violation: Native module cannot be null.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:204:6 in guardedLoadModule
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:263808:3 in global code

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError

Then, after opening an issue in GitHub the author suggested my to install:

yarn add react-native-onesignal

Here is the Issue on Github.Then I started getting:

iOS Bundling failed 3417ms
Unable to resolve module fs from /Users/giulioserra/Documents/App/CTS/node_modules/onesignal-expo-plugin/build/onesignal/withOneSignalIos.js: fs could not be found within the project or in these directories:
  node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  29 | exports.xcodeProjectAddNse = exports.withOneSignalIos = void 0;
  30 | const config_plugins_1 = require("@expo/config-plugins");
> 31 | const fs = __importStar(require("fs"));

I cleared the cache but nothing, It seems so strange since fs package should be included in every node release as far as I know, and suggestions?

Giulio Serra
  • 253
  • 1
  • 6
  • 15
  • Hi! are you using managed workflow? a link to another sample https://github.com/OneSignalDevelopers/OneSignal-ReactNative-Expo-Sample here's a step by step guide https://onesignal.com/blog/how-to-add-android-push-notifications-to-your-react-native-expo-app/ – Patricio Vargas Mar 02 '22 at 22:49
  • 1
    Hi there, I can confirm is a managed workflow. For now I switched to Expo notifications because I really need to deploy my app, I let you know later on ;) – Giulio Serra Mar 14 '22 at 12:25

0 Answers0