You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using sockjs-client in dev mode with vite, I get the following error:
TypeError: crypto.randomBytes is not a function
at Object.string (random.js:11:1)
at Object.unloadAdd (event.js:39:1)
at XHRCorsObject.AbstractXHRObject._start (abstract-xhr.js:48:1)
at abstract-xhr.js:21:1
Without the fix, the file looks empty (and therefore, crypto.randomBytes is undefined)
import{__esm,__export}from"./chunk-6DBBYCL5.js";// browser-external:cryptovarcrypto_exports={};__export(crypto_exports,{default: ()=>crypto_default});varcrypto_default;varinit_crypto=__esm({"browser-external:crypto"(){crypto_default=newProxy({},{get(){thrownewError('Module "crypto" has been externalized for browser compatibility and cannot be accessed in client code.');}});}});export{crypto_exports,init_crypto};//# sourceMappingURL=chunk-VW2V5EWT.js.map
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
Describe the bug
When using sockjs-client in dev mode with vite, I get the following error:
(Same error, but different issue: sockjs/sockjs-client#575)
In production mode (e.g. vite preview) it works without problems.
I think this is a bit similar to #8141, because my guess is that it has to do with the
browser
field, which is set in sockjs-client as:When I change my vite config like this, it works, but I'm not sure if that is a good idea
Any ideas?
Reproduction
https://stackblitz.com/edit/vitejs-vite-8purpq
System Info
Used Package Manager
yarn
Build output
With the above workaround, the referenced file in the build looks fine:
Without the fix, the file looks empty (and therefore, crypto.randomBytes is undefined)
Validations
The text was updated successfully, but these errors were encountered: