node-xml2js
node-xml2js copied to clipboard
Unable to use with vite as vite doesn't support require statement
Vitejs doesn't support require statement which is used inside xml2js
module ref
there should be a migration done for ESmodules
Try window.require() bur not require()
Has anyone tried the result of running decaffeinate on this? The rollup incompatibility is particularly annoying.
Having same issues with Vite 2.8.0 when trying to use xml-js package. However, the solution I found was to get rid of Vite and go with Rollup (which is what Vite uses internally). The biggest drawback is that for live-editing/debugging Vite is much faster than Rollup for my project (1 sec compared to 30s).
package.json using rollup:
The rollup.config.js had to be modified by adding @rollup/plugin-commonjs
and @rollup/plugin-node-resolve
//rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
...
plugins: [
...
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte'],
preferBuiltins: false
}),
commonjs(),
...
],
...
https://github.com/rollup/plugins/tree/master/packages/commonjs