Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES Module Format Support #5735

Open
manuelroth opened this issue Aug 8, 2024 · 3 comments
Open

ES Module Format Support #5735

manuelroth opened this issue Aug 8, 2024 · 3 comments

Comments

@manuelroth
Copy link

manuelroth commented Aug 8, 2024

Problem Description
I am using Vite as a bundler. Vite expects ES Module by default. CommonJS Format is automatically transformed to ES Module during development builds. But somehow I can't get it working with formiojs for production builds. It results in exports is not defined Error:
image. I guess this error originates in Vite not being able to convert formiojs from CommonJS to ES Module during production build. Therefore it still contains exports/require after bundling.

Currently formiojs only supports CommonJS as output format. When are gonna support ES Module output format?

Possible Solution
In addition to CommonJS format, also support ES Module format. So Vite could directly use this version instead of having to do the conversion by itself.

@manuelroth
Copy link
Author

I just saw that you are already referencing to an ES Module version in your package.json. Although import is also pointing to the CommonJS variant. I think this is wrong. Maybe that is the reason why Vite is confused?
Bildschirmfoto 2024-08-08 um 18 02 19

@manuelroth
Copy link
Author

I opened a PR to correct the above issue: #5736

@manuelroth
Copy link
Author

manuelroth commented Aug 9, 2024

In case somebody else encounters this issue using Vite. I was able to work around it by forcing Vite to convert formiojs and its dependencies to ES Module using @rollup/plugin-commonjs:

import commonjs from '@rollup/plugin-commonjs';

export default defineConfig({
  plugins: [
    commonjs({
      include: [
        /node_modules\/formiojs(\/|\/node_modules\/).*/, // Include formiojs and all sub-dependencies
      ],
    }),
    ...

I shouldn't have to this if formiojs would be configured correctly. Please have a look into this. Many people are moving on from Webpack to Vite and will run into this issue. It would be ideal if you provide the library in ES Module format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant