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

fix!: Remove browser field from package.json #2255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wkelly17
Copy link

Remove browser field from package.json of core packages so that worker export doesn't get mapped back the browser field by Vite, Rollup, Webpack etc;

BREAKING CHANGE: Jest was previously mentioned as the reason that wasn't removed, but Jest now supports package.json modules. That said, some other tooling might still not support esm exports.

Summary

A couple of years ago, it was noted that rollup, vite, and webpack map the worker export condition back to the browser field, which broke solid in certain edge runtimes (cloudflare) due to the need to load the server build of solid instead of the browser field. (notably, esbuild does not follow that behavior) Issues were opened with the respective bundlers, but vite closed as expected, and rollup didn't respond at the time. The fix as noted was to remove the browser field from pacakge.json, but it was noted that would break Jest and other non esm envs, which didn't support exports, but now they (Jest) do. (And esm adoption has continue to increase)
Full discussion of the issue here:
solidjs/solid-start#263

Recently, the cloudflare adapter for astro removed their esbuild step, which resulted in breaking the adapter for users of solid bringing this back to attention. Context here:
withastro/adapters#224

Jest however, now supports package.json exports:
https://jestjs.io/blog/2022/04/25/jest-28#packagejson-exports,
and allows configuring how the exports of a package.json are resolved:
https://jestjs.io/blog/2022/04/25/jest-28#packagejson-exports

How did you test this change?

Here is an example repo showing Jest working with solid, while I've remove the browser field in a patch:
https://github.com/wkelly17/Solid-Jest-repro

Besides Jest now working, this would fix workarounds for users of cloudflare + astro + solid, and I think for anyone trying to bundle for Cloudflare using anything other than esbuild (and maybe some other edge runtimes? uncertain).

The main question I'm not sure about is, are there any other common community packages besides Jest that would preclude from making this merge now that some upstream issues have solved?

… worker export doesn't get mapped back to removeBrowserPackageJson

BREAKING CHANGE: Jest was previously mentioned as the reason that wasn't removed, but Jest now supports package.json modules. That said, some other tooling might still not support esm exports.
Copy link

changeset-bot bot commented Aug 16, 2024

⚠️ No Changeset found

Latest commit: 23a16eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Successfully merging this pull request may close these issues.

1 participant