OneSignal/react-onesignal

[Bug]: Uncaught (in promise) Error: You need to provide your OneSignal appId.

pedroaurelli opened this issue · 2 comments

What happened?

Hi, i´ve a React (NextJS) application and i want to push some notifications to my users, but the OneSignal is not work in my QA application which is deployed in Azure DevOps. Its only works in my localhost oppened at 3000 port. How do i fix this?
My OneSignal appId is inside an enviroment file both locally and in qa.
In my OneSignal web-settings, the URL which was defined is my QA app, but when i change this to localhost its works perfectly

// init OneSignal in my _app.tsx file

useEffect(() => {
  OneSignal.init({ appId: process.env.NEXT_PUBLIC_ONESIGNAL_APP_ID || '' })
}, [])

Steps to reproduce?

1. Install react-onesignal package
2. Move OneSignalSDKWorker.js file to public folder  
3. Init OneSignal in _app.tsx file with useEffect hook
- 3.1. Create a .env.development.local and declare OneSignal appId as enviroment variable, in my deployed app i put the same enviroment variables
4. Deploy my app and wait build process
5. Error: You need to provide your OneSignal appId.

What did you expect to happen?

Expect to OneSignal works and show to users a push slide prompt

Relevant log output

Uncaught (in promise) Error: You need to provide your OneSignal appId.
    at _app-43f2d96f5f6b22f9.js:172:89514
    at new Promise (<anonymous>)
    at Object.init (_app-43f2d96f5f6b22f9.js:172:89453)
    at _app-43f2d96f5f6b22f9.js:172:99679
    at Ui (framework-93b89dc25365d5c7.js:1:104667)
    at t.unstable_runWithPriority (framework-93b89dc25365d5c7.js:1:122637)
    at Ql (framework-93b89dc25365d5c7.js:1:44986)
    at Fi (framework-93b89dc25365d5c7.js:1:104128)
    at bi (framework-93b89dc25365d5c7.js:1:95618)
    at framework-93b89dc25365d5c7.js:1:45209

Howdy,
It looks like it's coming from this line.

So it seems that the options object is missing or the appId is missing. You're clearly passing in an options object so that means your environment variable is not being set.

Closing due to no response