preactjs / preset-vite

Preset for using Preact with the vite bundler
https://npm.im/@preact/preset-vite
MIT License
262 stars 26 forks source link

Error when updating to v2.8.2 #115

Closed tomosterlund closed 8 months ago

tomosterlund commented 8 months ago

Hey there. Thanks for this plugin :)

I wanted to update to v2.8.2, but my test pipeline keeps failing with the following error message:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/schedule-x/schedule-x/node_modules/stack-trace/index.js from /home/runner/work/schedule-x/schedule-x/node_modules/@preact/preset-vite/dist/cjs/prerender.js not supported.

Here the full logs: https://github.com/schedule-x/schedule-x/actions/runs/8322035817/job/22769189509?pr=297

It suggests that I should use a dynamic import instead of a require statement. Only thing is: this does not make sense for my setup. I'm using ESM and am importing @preact/preset-vite as an ES module.

rschristian commented 8 months ago

What version were you on prior? Ah, 2.8.1, asked too quick.

Well, you are using the CJS build, per the error.

rschristian commented 8 months ago

You'll need to either add "type": "module" here or convert this to be e2e.vite.mts. Without it, that is treated/compiled to CJS.

Not that this isn't a legitimate issue on our end, our CJS builds are incorrect. Need to dynamically import stack-trace I suppose.

tomosterlund commented 8 months ago

You're right, thanks a lot. This worked perfectly :) I would say error is on my end then too.

This resolves it for me. Do you want the issue open still if something is broken in the CJS build?

rschristian commented 8 months ago

Let's keep it open, our CJS build is busted.

It's not a problem on your end necessarily, you're just not consuming our ESM build is all. Even if you intended to have an ESM config, we're shipping something that doesn't work in a target we're meant to be supporting, so mistake is on our end even if you can work around it.

Thanks for reporting!