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

Require error #9

Closed
ishetnogferre opened this issue Dec 13, 2022 · 7 comments
Closed

Require error #9

ishetnogferre opened this issue Dec 13, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@ishetnogferre
Copy link

Describe the bug

In a Craft & Vite project after following the docs and including the standard setup in the vite.config.js plugins section, following error keeps showing after running the commands for serving or building:

Error [ERR_REQUIRE_ESM]: require() of ES Module /XXX/XXX/node_modules/critical/index.js from /XXX/XXX/node_modules/rollup-plugin-critical/dist/index.js not supported.
Instead change the require of /XXX/XXX/node_modules/critical/index.js in /XXX/XXX/node_modules/rollup-plugin-critical/dist/index.js to a dynamic import() which is available in all CommonJS modules.

To reproduce

Steps to reproduce the behaviour:

  1. A Craft CMS setup with vite plugin installed
  2. Add this plugin
  3. Run "vite" or "vite build"
  4. Error in console

Expected behaviour

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Versions

  • Plugin version: 1.0.10
  • Craft version: 4.3.4
@ishetnogferre ishetnogferre added the bug Something isn't working label Dec 13, 2022
@jmartsch
Copy link

Same here but with ProcessWire as a CMS.

@khalwat
Copy link
Contributor

khalwat commented Dec 13, 2022

Yep, I'm fixing it right now... it should be bundled as CommonJS by default, not ESM.

khalwat added a commit that referenced this issue Dec 13, 2022
…t should be CommonJS for broader (and backwards) compatibility ([#9](#9))
khalwat added a commit that referenced this issue Dec 13, 2022
@khalwat
Copy link
Contributor

khalwat commented Dec 13, 2022

Well, that was fun. The actual issue was that the critical package moved to be ESM-only, and rollup-plugin-critical is shipped with both CJS and ESM versions.

So I had to dynamically import the critical ESM into rollup-plugin-critical to allow it to work for both CJS and ESM builds.

The current tests all passed, because they operate on the ESM build; I'll have to investigate that further at some point, to see if I can add a real-world test trying to import and use rollup-plugin-critical for both ESM and CJS.

Fixed in 1.0.12 -> https://github.com/nystudio107/rollup-plugin-critical/releases/tag/1.0.12

@khalwat khalwat closed this as completed Dec 13, 2022
@jmartsch
Copy link

jmartsch commented Dec 13, 2022

I updated to latest version, but the error still occurs to me. Deleted node_modules and reinstalled everything.

image

@khalwat
Copy link
Contributor

khalwat commented Dec 13, 2022

@jmartsch please verify that the new version is actually installed?

I've tested this on an external project that demonstrated the issue, and it worked fine. You might try nuking your node_modules directory and package-lock.json and installing from scratch.

@jmartsch
Copy link

Deleted package-lock.json and reinstalled. Throws no error now, but also seems to not generate the crititcal-css. But might be another problem on my side. I am checking tomorrow.

@khalwat
Copy link
Contributor

khalwat commented Dec 13, 2022

FWIW, the test project I mentioned generated the critical CSS properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants