svimg: Bug: require() is trying to import an ES Module
Description:
In Sveltekit, after installing svimg (pnpm i svimg) as dependency, running pnpm dev does not work.
error when starting dev server:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/-/-/node_modules/.pnpm/svelte@4.2.0/node_modules/svelte/src/runtime/ssr.js from /Users/-/-/node_modules/.pnpm/svimg@3.2.0/node_modules/svimg/dist/index.js not supported.
Instead change the require of ssr.js in /Users/-/-/node_modules/.pnpm/svimg@3.2.0/node_modules/svimg/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/-/-/node_modules/.pnpm/svimg@3.2.0/node_modules/svimg/dist/index.js:15:14)
 ELIFECYCLE  Command failed with exit code 1.
Versions
- Node: 18.16.0
- pnpm: 8.6.1
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 6
- Comments: 16 (2 by maintainers)
Thanks for the offer, but I think I’ve gotten the necessary changes completed. Current git is now ESM, hoping to do a release in the next day or so.
The problem is that Svelte 4 moved to be pure ES modules, whereas svimg still builds CommonJS modules by default. (svimg does provide ES modules as well, but in a sort of nonstandard way from before Node settled on its standard ESM support)
I’m working on converting svimg to pure ESM. It’ll have to be a major version breaking change.