ljharb / qs

A querystring parser with nesting support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use qs with Vite bundler

olivierbaudouin opened this issue · comments

I try to use qs with Nuxt3, but Vite breaks on the first require in the package

import * as qs from 'qs'  
qs.stringify(someObject, {encodeValuesOnly: true})
// --> "require is not defined"

Is it possible to adapt qs to Vite?

No, but it’s possible to adapt vite to the majority of the ecosystem (which is CJS). I believe there’s a plugin for it.

@ljharb, are you considering adding an ESM build in the future?

The Node.js ecosystem is mostly CJS but already supports both module systems. For in-browser applications, ESM is the default way. Even though bundlers work with CJS, ESM modules enable tree-shaking and direct imports via import maps. It could be beneficial for the library to have an ESM build. I can help you with this if you think it's a good idea.

No, there would be no value in doing so, and lots of downsides.

For browsers, a bundler should be able to handle CJS just fine, and tree-shaking works precisely as well with CJS as with ESM, and import maps are unnecessary with a bundler.