-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server version is used in browser when bundled with Vite #641
Comments
Hi @thekevinbrown! Your question seems related to #568, so I'll link that, but there's not a specific answer for you there. Can you be more specific about the semantics you'd like to see? We have both a server bundle and a browser bundle, and as the Vite team pointed out, there aren't hard standards for how to define the bundles. |
Hi @swiftone, I'd like it so when I do this: import { OktaAuth } from '@okta/okta-auth-js';
const oktaAuthClient = new OktaAuth(oktaAuthOptions); I get the browser version in Vite. Increasingly we'll need ESM in both browser and server, so in the long run this approach where
|
Thanks for the response - We've definitely had discussions about how to best manage the not-quite-isomorphic nature of this package, so I'll add this issue into those discussions, but there isn't a short-term plan to change this yet. As a workaround until then, can you make a local module that pulls in the okta code as it demands and then exports that in a way that Vite is happy with? |
Internal ref: OKTA-375389 |
@swiftone, no, unfortunately that's not a good workaround as whenever I import the module I get the server version. If I import the UMD directly, then Typescript doesn't get the types for the module. The only workaround I've found is to alias
resolve: {
alias: [
{
find: "@okta/okta-auth-js",
replacement: require.resolve("@okta/okta-auth-js/dist/okta-auth-js.umd.js"),
},
],
}, Which is pretty gross, but does work. |
While yes, there are no standards for fields like Vite already uses this and we're adopting it into WMR right now as is Yarn (might actually already be in use in Yarn). Adding the Adding |
@rschristian - thanks for the detailed writeup, I'll definitely include this in our discussion. |
Close this issue as okta-auth-js v5 exposes isomorphic APIs. |
@cmacdonnacha It's a known issue with the ESM bundle of okta-auth-js, as a workaround, please config vite to load the |
Ok thanks @shuowu |
This issue saved my bacon, thanks all! It was a long journey to find this answer though, I'm adding the full text of the error in the hope that others will find it more easily.
|
also ran into this issue. Quite painful and hard to track down. Should maybe leave this open or highlight it in the docs |
The fix for me was to add
|
I've just hit this issue:
vitejs/vite#2329
Would it be possible to update the
package.json
semantics so that this is easier for consumers of the package?The text was updated successfully, but these errors were encountered: