koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

Replace CommonJS with ES6 imports #419

Closed ppmathis closed 10 months ago

ppmathis commented 10 months ago

Thank you for your work on this library. I am trying to use it in a Vue 2 project which uses Vite and has been configured to use ES6 modules via "type": "module" in package.json . Unfortunately this kind of setup is currently not working with vuetify-jsonschema-form as the source code within the repository mixes CommonJS and ES6 imports.

With a regular Vue CLI based toolchain this works just fine as Babel will end up transforming all of them into one format, but with a Vite-based stack and no Babel the usage of this library is sadly not possible.

Would it be possible to have these changes merged and released as a minor version? I am currently running a fork to have vjsf working, but it would be wonderful to rely on upstream again. The changes themselves should be fairly minor and simply replace the few occurrences of CommonJS imports with proper ES6 module imports - like most of the library already are.

albanm commented 10 months ago

Thanks. I merged but npm publish hangs, I don't know why. I will try again tomorrow.

ppmathis commented 9 months ago

@albanm Thanks a lot for merging this so quickly. 🎉 Have you also considered marking your package for ES6 modules with "type": "module" as well, now that everything is using ESM? I am not sure right now if this would have any effect on a normal Vue installation, but using vjsf with Vitest results in this warning:

Module /xxx/node_modules/@koumoul/vjsf/lib/mixins/MarkdownEditor.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@koumoul/vjsf" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

It's not breaking the unit tests as Vitest supports a workaround for such packages, but it might be worth considering to have this fixed as well - assuming it will not break any regular Vue2-based projects.

albanm commented 9 months ago

I am always a little wary of these kind of changes outside of major versions. Honestly I hate the whole mess of publishing libs : pre-built/as source, commonjs/esm, with types, etc.

Anyway I don't plan on taking any risk refactoring the v2. But I am currently working on v3, there will be an alpha version coming in a few weeks (hopefully). We will try to make everything right for this version by keeping alpha/beta opened for a while and take some developer feedback.

albanm commented 9 months ago

v2.22.0 is available

rFranzr commented 9 months ago

@ppmathis thanks for this pull-request. I am currently migrating a vue2 webpack to a vue2 vite project. How are you importing vjsf in Vite? I am getting an ambiguous indirect export error when calling a route with a form.

ambiguous indirect export: VJsf

Edit: For people reading this later as it might help you: I tried two things: