-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Vite unable to use npm xml-js package: Cannot read properties of undefined (reading 'prototype') at sax.js:222:46 at node_modules/sax/lib/sax.js #7555
Comments
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This solution worked for me. |
It works with build but it does not work during dev. This part becomes like this after optimization. var Stream;
try {
Stream = (init_stream(), __toCommonJS(stream_exports)).Stream;
} catch (ex) {
Stream = function() {
};
} // browser-external:stream
var stream_exports = {};
__export(stream_exports, {
default: () => stream_default
});
var stream_default;
var init_stream = __esm({
"browser-external:stream"() {
stream_default = new Proxy({}, {
get() {
throw new Error('Module "stream" has been externalized for browser compatibility and cannot be accessed in client code.');
}
});
}
}); If |
I don't know why this only throws error with vite/packages/vite/src/node/optimizer/esbuildDepPlugin.ts Lines 198 to 211 in adacaba
Maybe it is safe to change export default to module.exports = ? (not sure if it works)Since require('externalized').foo will throw error when externalized was not resolved.
|
For a workaround, aliasing // vite.config.js
export default defineConfig({
resolve: {
alias: {
'stream': 'stream-browserify'
}
}
}); |
I think https://github.com/vitejs/vite/pull/6493/files#diff-7657c7c3217417a1747348410996718b471f6f0cb9552752b47a411f8f010830R207-R224 may address this, though I haven't took the time to look into it yet. The PR is mixed with a fix for yarn pnp. |
I have also run into this problem when I added
It works in both |
Describe the bug
Current web app project using Rollup and am able to use the xml-js package to build the web app, however, when trying to switch Vite, the web app fails to load and Vite produces no errors, however, in the console I get the error below at runtime. I reproduced this using the simplest Vite+Vue app on stackblitz (see link below).
Text:
xml-js: https://www.npmjs.com/package/xml-js
It appears that it fails to package Stream, but Rollup can package it, and I understand Vite uses Rollup internally, so I'm confused as to why this is failing.
When reproducing using the stackblitz web IDE, please open console to see the error.
Reproduction
https://stackblitz.com/edit/vitejs-vite-fm1ze8
System Info
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: