mvolfik / svelte-photoswipe

A small library that wraps PhotoSwipe v5 into a Svelte component
https://mvolfik.github.io/svelte-photoswipe/
MIT License
8 stars 1 forks source link

Unexpected token 'export', cjs error with ESM #3

Open joshwalker9115 opened 1 year ago

joshwalker9115 commented 1 year ago

I'm getting the following error when trying to use the standard example in my sveltekit project.

Internal server error: Unexpected token 'export'
      at internalCompileFunction (node:internal/vm:73:18)
      at wrapSafe (node:internal/modules/cjs/loader:1176:20)
      at Module._compile (node:internal/modules/cjs/loader:1218:27)
      at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
      at Module.load (node:internal/modules/cjs/loader:1117:32)
      at Module._load (node:internal/modules/cjs/loader:958:12)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
      at ModuleJob.run (node:internal/modules/esm/module_job:194:25) (x2)
/[...personal_path...]/node_modules/photoswipe/dist/photoswipe.esm.js:5190
export default PhotoSwipe;
^^^^^^

It looks like this has to do with cjs vs esm exports. I was able to fix the issue by updating the following files:

node_modules/photoswipe/dist/photoswipe-lightbox.esm.js:1153

export  default PhotoSwipeLightbox;
export { Content, ImageContent };

to

module.PhotoSwipeLightbox = PhotoSwipeLightbox;
module.exports = { Content, ImageContent };

and node_modules/photoswipe/dist/photoswipe.esm.js:5190

export  default PhotoSwipe;
export { Content, ImageContent };

to

module.PhotoSwipe = PhotoSwipe;
module.exports = { Content, ImageContent };

Obviously this isn't any change to your files but is this something that can be addressed in patchPhotoswipe.cjs?

erskingardner commented 1 year ago

I'm now also getting this with the newest version of Photoswipe. (5.4.1)

erskingardner commented 11 months ago

@mvolfik any chance you'll be updating this library at all going forward?

mvolfik commented 11 months ago

Hey, sorry for the radio silence 🙃

To be honest, I don't expect to get back to this library anytime soon.

If you want the full story, I wanted to use photoswipe in a side project and figured I might wrap it into a ready-made Svelte component for others to use. But then I realized I need also the image heights for photoswipe, which aren't available in code with the way my asset backend is currently built. I started a rewrite to fix that (and other things there) a few months ago, but didn't finish it, and it's one of those things that I want to eventually get back to, but they are very low on the priority list. And until that is done, svelte-photoswipe isn't of much use to me. So I hope to return to this eventually, but that might take anywhere from weeks to years.

The complete code of the component itself is under 100 lines, so you might be better off to just inline it in your project (which also gets you more control over the styling etc). If you are interested in taking over the library and properly maintaining it, I'll be happy to hand the repo and npm package over.

erskingardner commented 10 months ago

No worries, and thanks for the context. I don't have time either to take over the project and in the end did just inlining the code in my project.