derrickreimer / fathom-client

A Fathom Analytics library to help with client-side routing
http://npm.im/fathom-client
MIT License
177 stars 18 forks source link

ESM exports issue in 3.7.0 #60

Closed toddheslin closed 3 months ago

toddheslin commented 3 months ago

👋 Hey @derrickreimer thanks for your work on this!

I upgraded to 3.7.0 and had some issues along the lines of:

[vite] Internal server error: [vite] Named export 'trackPageview' not found. The requested module 'fathom-client' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'fathom-client';
const {blockTrackingForMe, load, trackPageview} = pkg;

Unfortunately, I haven't been able to figure out exactly why but it's likely due to cd3d70b5a3fd56117116b82f2a308062406a163d

For now I've rolled back to 3.6.0 to keep on moving forward. Given there was no one else who reported this, and a good chunk of people are still using 3.6.0, I thought it would be good to stub an issue for anyone else to contribute their findings:

image

I'm using this package in a Remix app using Vite for build, spitting out ESM. The package.json is set type=module and I've confirmed that it's outputting ESM. For some reason it looks like it's resolving to the cjs version instead of esm.

derrickreimer commented 3 months ago

Thanks for the report @toddheslin! I bet you're right about that build process overhaul. I'll take a look at this and try to get a new version cut soon.

derrickreimer commented 3 months ago

@toddheslin playing around with some config changes. Could you try pointing your package.json to git://github.com/derrickreimer/fathom-client#3f91c60 (#61) to see if it'll grab the right export?

toddheslin commented 3 months ago

Yep, that works perfectly. Thanks @derrickreimer you've graduated in the world of pain known as cjs/esm for library authors 😂

derrickreimer commented 3 months ago

Great! 😅 version 3.7.1 released.