node-xml2js icon indicating copy to clipboard operation
node-xml2js copied to clipboard

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

Open gkanishk opened this issue 3 years ago • 3 comments

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

gkanishk avatar Jun 12 '21 07:06 gkanishk

Try window.require() bur not require()

Kenhuey avatar Jul 01 '21 04:07 Kenhuey

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

szakharchenko avatar Aug 03 '21 13:08 szakharchenko

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

rrabb avatar Apr 01 '22 02:04 rrabb