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

Add esm data to package json to fix #908 #1284

Closed

Conversation

matt-hernandez
Copy link

Changes

Add necessary package.json data to root and /react folder to fix compat issues between posthog and Remix with Vite. Fixes #908

This fix is based on what I had to do at my job to make posthog-js and posthog-js/react play nicely with our Remix w/ Vite app. Locally, tests passed, however e2e tests had some flakiness. My gut instinct tells me that the intermittent failures were not due to the changes to any of the package.json files.

Also this fix grew past what I thought it would originally be. By converting things to an ES module, several other files had to be renamed in order to be compatible with CommonJS format, specifically for ESLint. Will be watching Github actions to see if things complete without failure.
...

Checklist

  • [ *] Tests for new code (see advice on the tests we use)
  • [ *] Accounted for the impact of any changes across different browsers
  • [ *] Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Jul 3, 2024

@matt-hernandez is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines +135 to 137
"engines": {
"node": ">=20.1.0"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to bump the node version here?

we try to be pretty conservative with changes since it can be hard to predict consequence on other folks CI

is it this change that means we need the changes to eslint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i'm pretty sure we can support at least >=18 since that's what i'm using locally, i haven't tested with 16)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node version requirement is due to Cypress not running e2e tests with ESM unless it runs in node > 20.1.0. There may be another workaround, but in local, that was the only way I could get Cypress working.

ok, the version requirement bump is likely to be painful for an SDK. Node 18 isn't end of life until Apr 2025

but equally don't want to leave folk with your problem hanging...

maybe we can do this another way - we have an examples folder - you can see for e.g. the nextjs folder at https://github.com/PostHog/posthog-js/tree/main/playground/nextjs

could you open another pr with a vite/remix example - (as small as possible 😊)

that should let us see the problem and help us keep it working in future

(i've never touched remix or i'd offer to make one - but i'm guessing you'll do a better job 💖 )

@pauldambra
Copy link
Member

hey @matt-hernandez 👋

thanks for this! it's a little beyond me so a few questions to get started 😊

Comment on lines +29 to +41
"type": "module",
"exports": {
".": {
"types": "./dist/module.d.ts",
"import": "./dist/es.js",
"require": "./dist/module.js"
},
"./react": {
"types": "./react/dist/types/index.d.ts",
"import": "./react/dist/esm/index.js",
"require": "./react/dist/umd/index.js"
}
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've been sort of ignoring the module/bundling changes in JS since they seem pretty volatile and i was hoping for things to settle and i could learn it once 🤣

can you explain what this does/means?

i'm mostly wondering if we'll have unexpected consequences in other environments than you're testing for, i've found sometimes apparently benign changes throw up weird errors for folk

(my guess is this is safe but 🙈)

@matt-hernandez
Copy link
Author

@pauldambra The node version requirement is due to Cypress not running e2e tests with ESM unless it runs in node > 20.1.0. There may be another workaround, but in local, that was the only way I could get Cypress working.

The exports of the package.json files combined with ”type”: “module” help to label this package as an ESM compatible package, while also pointing bundlers that rely on CommonJS/UMD format which files to go to for their respective format type.

Unfortunately, by converting this repo to full ESM, the changes ballooned. Pretty much anything with CommonJS format is having to change. Eslint is also completely borked after the conversion to ESM. And I think the only stable way to fix it would be to bump up ESLint 9+ and convert .eslintrc.js to the more recommended eslint.config.js file with flat config.

I’m converting this to a draft in the meantime since changing everything to ESM represents more than just a few metadata changes.

@matt-hernandez matt-hernandez marked this pull request as draft July 4, 2024 18:01
@matt-hernandez
Copy link
Author

@pauldambra I've created PR #1293 to demo the issue from #908

@posthog-bot
Copy link
Collaborator

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@matt-hernandez
Copy link
Author

I’ll close this one since we have a different one open that’s demonstrating the underlying problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing pkg.exports in package.json
3 participants