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
See original GitHub issueDescribe 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:
Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
at sax.js:222:46
at node_modules/sax/lib/sax.js (sax.js:1565:1)
at __require (chunk-OL3AADLO.js?v=8029f249:9:50)
at node_modules/xml-js/lib/xml2js.js (xml2js.js:1:11)
at __require (chunk-OL3AADLO.js?v=8029f249:9:50)
at node_modules/xml-js/lib/index.js (index.js:3:14)
at __require (chunk-OL3AADLO.js?v=8029f249:9:50)
at dep:xml-js:1:16
| (anonymous) | @ | sax.js:222
| node_modules/sax/lib/sax.js | @ | sax.js:1565
| __require | @ | chunk-OL3AADLO.js?v=8029f249:9
| node_modules/xml-js/lib/xml2js.js | @ | xml2js.js:1
| __require | @ | chunk-OL3AADLO.js?v=8029f249:9
| node_modules/xml-js/lib/index.js | @ | index.js:3
| __require | @ | chunk-OL3AADLO.js?v=8029f249:9
| (anonymous) | @ | dep:xml-js:1
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
System: OS: Windows 10 10.0.18363
Binaries: Node: 14.16.0 - C:\Program Files\nodejs\node-v14.16.0\node.EXE
vite: ^2.9.0
Used Package Manager
npm
Logs
Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
at sax.js:222:46
at node_modules/sax/lib/sax.js (sax.js:1565:1)
at __require (chunk-OL3AADLO.js?v=8029f249:9:50)
at node_modules/xml-js/lib/xml2js.js (xml2js.js:1:11)
at __require (chunk-OL3AADLO.js?v=8029f249:9:50)
at node_modules/xml-js/lib/index.js (index.js:3:14)
at __require (chunk-OL3AADLO.js?v=8029f249:9:50)
at dep:xml-js:1:16
| (anonymous) | @ | sax.js:222
| node_modules/sax/lib/sax.js | @ | sax.js:1565
| __require | @ | chunk-OL3AADLO.js?v=8029f249:9
| node_modules/xml-js/lib/xml2js.js | @ | xml2js.js:1
| __require | @ | chunk-OL3AADLO.js?v=8029f249:9
| node_modules/xml-js/lib/index.js | @ | index.js:3
| __require | @ | chunk-OL3AADLO.js?v=8029f249:9
| (anonymous) | @ | dep:xml-js:1
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
javascript - TypeError: Cannot read properties of undefined ...
I've tried adding target: "node" to my "node_modules/react-scripts/config/webpack.config.js" But it won't work... Here's some ways I've already ...
Read more >@vitejs/plugin-react - npm
The all-in-one Vite plugin for React projects. enable Fast Refresh in development; use the automatic JSX runtime; avoid manual import React in ....
Read more >vite internal server error | The AI Search Engine You Control
So i figured it out, well, my boss of design did, all i had to do was delete the node_modules directory and run...
Read more >Getting Started - Vite
However, some templates require a higher Node.js version to work, please upgrade if ... npm 6.x npm create vite@latest my-vue-app --template vue #...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This solution worked for me.
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.