solid icon indicating copy to clipboard operation
solid copied to clipboard

fix!: Remove browser field from package.json

Open wkelly17 opened this issue 1 year ago • 1 comments

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: https://github.com/solidjs/solid-start/issues/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: https://github.com/withastro/adapters/issues/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?

wkelly17 avatar Aug 16 '24 15:08 wkelly17

🦋 Changeset detected

Latest commit: 06113dbc3870ac3049d34390af17b3edd230d9b1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
solid-js Minor
solid-element Major
test-integration Patch

Not sure what this means? Click here to learn what changesets are.

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

changeset-bot[bot] avatar Aug 16 '24 15:08 changeset-bot[bot]