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

Error "require() of ES Module not supported." after adding vite-plugin-glsl to vite.config.ts #26

Closed
felixniemeyer opened this issue Dec 12, 2022 · 8 comments
Assignees
Labels
duplicate Something was was pointed out before not an issue Something that doesn't need to be fixed

Comments

@felixniemeyer
Copy link

Hi, thanks for working on this!

Unfortunately, i stumble right at the beginning when trying to make this work.

If I add vite-plugin-glsl to my config like advised ...

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import glsl from 'vite-plugin-glsl';


// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    glsl(), 
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

... I get this error:

failed to load config from .../project/vite.config.ts
error when starting dev server:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../project/node_modules/vite-plugin-glsl/src/index.js from .../project/vite.config.ts not supported.
Instead change the require of index.js in .../project/vite.config.ts to a dynamic import() which is available in all CommonJS modules.
    at Object._require.extensions.<computed> [as .js] (file://.../project/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:63157:17)
    at Object.<anonymous> (.../project/vite.config.ts:35:39)
    at Object._require.extensions.<computed> [as .js] (file://.../project/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:63154:24)
    at loadConfigFromBundledFile (file://.../project/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:63162:21)
    at loadConfigFromFile (file://.../project/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:63020:34)
    at async resolveConfig (file://.../project/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:62643:28)
    at async createServer (file://.../project/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:61943:20)
    at async CAC.<anonymous> (file://.../project/node_modules/vite/dist/node/cli.js:707:24)

@felixniemeyer
Copy link
Author

Oh, I just realized somebody had the same issue over here: #22

Adding "type": "module" to the package.json worked out.

@UstymUkhman UstymUkhman self-assigned this Dec 18, 2022
@UstymUkhman UstymUkhman added not an issue Something that doesn't need to be fixed duplicate Something was was pointed out before labels Dec 18, 2022
@jakewhiteley
Copy link

@UstymUkhman can this be reopened? "type": "module" is not a good fix.

For instance I add that into my package.json, and then it causes issues with other vite plugins/node features:

Dynamic require of "file:///C:/wamp64/www/test/quick/node_modules/purgecss-with-wordpress/index.js" is not supported

and

Error: Dynamic require of "path" is not supported

Could you not just create an alternative entry point into your plugin for those of us who need to include it in a more standard way?

@UstymUkhman
Copy link
Owner

Hi @jakewhiteley, I can take a look at the best solution for this issue, but can you tell me first your node and vite versions, please? Also, you can take a look at this issue for possible workarounds at the moment.

@jakewhiteley
Copy link

@UstymUkhman I am using Vite 3.2.5 and node 16.14.0

@jakewhiteley
Copy link

I will also try on Vite 4.*

@UstymUkhman
Copy link
Owner

Ok, thanks! Can you also explain why the workarounds described in the issue I've linked above don't work in your case?

@rogersanick
Copy link

Hey @UstymUkhman - the work around listed above doesn't work in my case because it breaks Tailwind CSS :( Is there another option?

@UstymUkhman
Copy link
Owner

Hi @rogersanick! Thanks for using this plugin. If you're talking only about "type": "module", feel free to check this issue for other possible workarounds. If none if them will work, please consider creating a reproducible demo or linking an existing repo so I can take a look an find the best way to fix it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Something was was pointed out before not an issue Something that doesn't need to be fixed
Projects
None yet
Development

No branches or pull requests

4 participants