Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.84k stars 598 forks source link

Unable to use with vite as vite doesn't support require statement #613

Open gkanishk opened 3 years ago

gkanishk commented 3 years ago

Screenshot 2021-06-12 at 1 16 19 PM

Vitejs doesn't support require statement which is used inside xml2js module ref

there should be a migration done for ESmodules

Kenhuey commented 3 years ago

Try window.require() bur not require()

szakharchenko commented 2 years ago

Has anyone tried the result of running decaffeinate on this? The rollup incompatibility is particularly annoying.

rrabb commented 2 years ago

image

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: image

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