-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Pre-bundling dependency error #3736
Comments
but crypto which imported by okta-auth-js isn't supported in browser. |
From an
okta/okta-auth-js#768 (comment) Based on that comment, shouldn't Vite ignore pre-bundling the dep when used client side? As a SvelteKit user, I'm using both the |
Did some more digging, and it seems like lib/crypto/webcrypto.ts// ./node is swapped for ./browser in webpack config
export * from './node'; https://github.com/okta/okta-auth-js/blob/master/lib/crypto/webcrypto.ts webpack.common.config.js// This is the base webpack config that other configs build upon
var webpack = require('webpack');
module.exports = {
resolve: {
extensions: ['.js', '.ts'],
alias: {
'./node$': './browser' // use browser built-in objects and functions
}
},
}; https://github.com/okta/okta-auth-js/blob/master/webpack.common.config.js I'm a little out of my depth here as I'm not very familiar with webpack and vite. Should Vite be able to handle this scenario? |
Even I am facing similar issue while using Auth0, seems prebundling is the issue. As Auth0 library works well with Webpack |
In looking at @Clee681 's comment, I had the thought that if it's just an alias, that can be accomplished via resolve.alias in the vite config file: {
resolve: {
alias: [
{
find: /^@okta\/okta-auth-js$/,
replacement: './node_modules/@okta/okta-auth-js/esm/index.js',
},
],
},
} I'm pretty sure this is the way the module should be resolved for SPA usage, not sure how we'd do this for SSR. With this in place, the dev server runs and the build succeeds. Still have to set up a sample app to really test things, but if this is even a small step in the right direction, it's worth sharing. UPDATE: I may have been premature - it looked like it worked for a moment, but now it's failing again. Not sure why. |
Based on an old comment by Evan here Using this for my alias got me past the build errors. I am using @okta/okta-vue @5.0.1 ... but not doing SSR though. resolve: {
alias: {
'@okta/okta-auth-js': '@okta/okta-auth-js/dist/okta-auth-js.umd.js',
}
} |
same issue with library @truffle/contract |
This may be fixed by #6493 with its changes to the browser-external proxy |
Describe the bug
I am using a library (
okta-auth-js
) that I think has support for bothnode
and thebrowser
. I'm trying to use the library both client-side and server-side via SvelteKit. I think the pre-optimization step is not bundling the dependency properly based on the below error.Reproduction
I created a bare bones reproduction using just Vite here: https://github.com/Clee681/okta-esm-module-repro
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: