Repository navigation
fix(deps): require use-sync-external-store ^1.5.0 so the ESM build loads in Node - #846
Conversation
…ads in Node dist/index.js imports `use-sync-external-store/shim`, which is kept external. Before 1.5.0 the package had no `exports` map, so Node's ESM resolver treats `/shim` as a directory and throws ERR_UNSUPPORTED_DIR_IMPORT. That breaks anything that loads the ESM build without a bundler: Vitest tests in apps that use reactfire, SSR that keeps dependencies external, and plain Node scripts. The CJS build is fine. Raise the floor to ^1.5.0 (lockfile: 1.2.0 -> 1.7.0).
4c3270c to
4463c3f
Compare
tyler-reitz
left a comment
There was a problem hiding this comment.
Approving. Your table reproduces with packed tarballs in a "type": "module" app (React 18, firebase 12, Node 22):
| reactfire | use-sync-external-store |
import('reactfire') |
|---|---|---|
main |
1.2.0 pinned | ERR_UNSUPPORTED_DIR_IMPORT |
main |
unpinned (1.7.0) | 74 exports |
| this PR | 1.2.0 pinned (npm nests 1.7.0) | 74 exports |
| this PR | 1.4.0 pinned (npm nests 1.7.0) | 74 exports |
| this PR | 1.5.0 pinned (deduped) | 74 exports |
A Vitest test importing reactfire fails to load on main + 1.2.0 and passes on this PR.
React 16 and 17 still work. With 16.14.0 and 17.0.2 (no native useSyncExternalStore), the 1.7.0 shim falls back and useObservable both server-renders and updates on the client under jsdom. Breaking the shim's fallback makes that test throw, so it really goes through the shim.
src only uses the three-argument useSyncExternalStore from /shim, so nothing depends on 1.2.x behavior. fix: is right too: the floor moves, but the supported React range doesn't change.
This branch predates #766 and #794, so CI never ran the package gate or the React 19 legs on it. Merged onto current main, publint --strict, attw and size-limit pass, and the useObservable tests pass on React 18 (21/21) and 19.3.1 (20, plus the #793 skip).
Non-blocking:
- A consumer that pins an older copy now ends up with a second, nested copy of the shim. It's small and stateless, so that should be harmless (inference).
- Importing
use-sync-external-store/shim/index.jsinstead would also fix it without moving the floor: under Node ESM it loads on both 1.2.0 and 1.7.0. I haven't checked it against the Next.js case that made the shim external, so the floor bump seems like the safer fix.
Summary
dist/index.jsimportsuse-sync-external-store/shim. The import stays external on purpose: inlining the shim broke Next.js, seevite.config.ts. Versions ofuse-sync-external-storebefore 1.5.0 have noexportsmap, so Node's ESM resolver treats/shimas a directory and won't load it:Bundlers resolve directory imports, so browser builds are fine. It breaks anything that loads reactfire's ESM build with Node's own resolver, for example:
node_modulespackages with Node directly, so the whole test file fails to load.The CJS build (
require('reactfire')) isn't affected.reactfire declares
^1.2.0, so fresh installs usually get a newer version. But any project that ends up with an older copy (from an existing lockfile, or another package that pins it) is broken. This repo's own lockfile still had 1.2.0.Changes
use-sync-external-storeto^1.5.0, the first version with anexportsmap (./shim→./shim/index.js). The lockfile now resolves 1.7.0. 1.5.0+ also lists React 19 in its peer range; 1.2.0 stopped at React 18.Testing
A consumer project that pins
use-sync-external-store, importing the packed tarball:use-sync-external-storeinstalledmain(^1.2.0)ERR_UNSUPPORTED_DIR_IMPORT^1.5.0)^1.5.0)Also:
import('reactfire')fails onmain. With this change it loads all 74 exports on both Node 22 and 24.tsc(src and tests) and the full emulator test suite pass. So does the React 19 type-check setup.