-
Notifications
You must be signed in to change notification settings - Fork 232
Production Build failing due to TypeError: Cannot read property 'emit' of undefined #846
Comments
I saw the same issue... seems to be a bug that was introduced in one of the recent commits. In our case, downgrading to 3.0.2 seems to have fixed the issue |
@mahesha-perpetualny @rupeshbhatti
I reproduced the issue in jest test environment in okta/samples-js-react#129. Wondering are you doing SSR in your app? |
I see this error after upgrading from |
@arminhaghi The issue is the bundler (like webpack) pickup the server bundle instead of the browser one in SSR. Then with the latest change, the As said in the OKTA REACT SDK readme, it's not suggested to use the SDK for SSR. Some workarounds you can try:
|
Internal Ref: OKTA-322595 |
In my case the app isn't using SSR |
@rupeshbhatti You can check which
Then you should be able to see log like okta/samples-js-react#129, check the If that's the case, you probably want to check the configure of the bundler to see why it's picking server bundle instead of the browser one. |
@shuowu We're using Next.js, which mixes SSR and client side. We've had the same issue and I can verify the userAgent field contains the word server in it :(. This seems to be happening on the Next pre-render stage. We've included the Next.js manages the webpack, so I'm not sure if we can mess around with it. Moving |
@ekasprzyk - I'm not familiar with the details of Next.js (it's been on my personal to-do list for...a while), so I can't say too much, but the key issue seems to be that you're using the server-based auth-js, but okta-react expects the browser-based auth-js. okta-react wasn't built with SSR in mind, and there are numerous complexities involved if you're trying to mix SSR and client-side rendering. My rough guess would be to use the server-based auth-js and don't use okta-react if you intend to have SSR of your app, as okta-react isn't yet built with SSR in mind. |
I ran into this issue because our PWA initializes a bunch of sagas while bootstrapping, including an identity saga calls an |
@scott-joe If building using another tool, you may need to adjust the config so it uses the "browser" entrypoint for this module. If you are using jest, the "moduleNameMapper" config will help:
|
We moved some things around, and now the Auth component isn't being kicked off by the init saga, but just to keep everything happy, we added this |
We just ran into this again after someone had to format their machine. If you run a test in VSCode using the little 'run' button within the test file, it'll follow what preferences you have set for Some lessons you have to learn twice... |
@scott-joe - I have definitely had the experience of having a problem that feels vaguely familiar, googling it, and finding a comment I left for my future self explaining what to do :). I (and I'm sure others) appreciate that you didn't DenverCoder9 this: https://xkcd.com/979/ |
I'm submitting this issue for the package(s):
I'm submitting a:
Current behavior
Build is failing due to latest release from 3.0.1 to 3.0.3
TypeError: Cannot read property 'emit' of undefined
at AuthService.emit (/home/ubuntu/frontend/node_modules/@okta/okta-react/dist/AuthService.js:558:30)
at AuthService.emitAuthState (/home/ubuntu/frontend/node_modules/@okta/okta-react/dist/AuthService.js:188:12)
at AuthService.clearAuthState (/home/ubuntu/frontend/node_modules/@okta/okta-react/dist/AuthService.js:181:12)
at new AuthService (/home/ubuntu/frontend/node_modules/@okta/okta-react/dist/AuthService.js:84:10)
at /home/ubuntu/frontend/node_modules/@okta/okta-react/dist/Security.js:29:33
at Object.useMemo (/home/ubuntu/frontend/node_modules/react-dom/cjs/react-dom-
Environment
node -v
): 12.15.0The text was updated successfully, but these errors were encountered: