feat(ra-data-simple-prisma): add /server subpath export to keep react-admin out of server bundles#113
Open
dan2811 wants to merge 1 commit into
Conversation
The package previously exposed both the client-side `dataProvider` and
the server-side request handlers from a single bundle. The bundle
includes `import { HttpError } from 'react-admin'` at the top, so any
Next.js serverless function importing `defaultHandler` (or any other
handler) transitively pulls in `react-admin`, `ra-core`,
`ra-ui-materialui`, and `react-router-dom`. None of this is needed at
runtime on the server, but it inflates the Lambda bundle and triggers
ESM resolution failures on Vercel when NFT traces `dist/index.js` while
Node ESM resolves to `dist/index.mjs`.
Split the package into two entry points via subpath exports:
- `ra-data-simple-prisma` -> client-side `dataProvider`
- `ra-data-simple-prisma/server` -> server-side handlers only,
no `react-admin` import
The top-level entry continues to re-export everything for backwards
compatibility. `react-admin` is now an optional peer dependency so
server-only consumers do not get install warnings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I was having an issue with a project that uses this package and I've had to resolve temporarily, using resolutions in my package.json. Have used claude to raise this PR which fixes my issue. Would be great if you could consider merging.
Disclaimer: I haven't looked in-depth at this code and I'm not familiar with this repo, so please review carefully! Hopefully it's not just AI slop!
Summary
ra-data-simple-prismaexposes both a client-sidedataProvider(usedby react-admin in the browser) and server-side request handlers (used
inside Next.js API routes to talk to Prisma directly) from a single
bundle. That bundle has a top-level
import { HttpError } from 'react-admin'which is only used by the client
dataProvider, but because it sits atthe top of
dist/index.js/dist/index.mjs, any server-side importof a handler transitively pulls in
react-admin,ra-core,ra-ui-materialui, andreact-router-domat runtime.On Vercel / Next.js this causes two real problems:
never executes.
react-router-dom@7.xthe package's
exportsfield causes Next.js NFT (file tracer) toinclude
dist/index.js(CJS) while Node ESM resolution at runtimepicks
dist/index.mjs— the missing.mjsis then never traced andthe function crashes with
MODULE_NOT_FOUNDin production.Fix
Split into two entry points via subpath exports:
react-admin?ra-data-simple-prismadataProvider+ handlers (back-compat)ra-data-simple-prisma/serverServer-side consumers can switch to:
and
react-admin(plus its transitive UI deps) disappears from thefunction's traced files entirely.
Changes
src/server.tsentry that re-exports only the server APIs.Http.ts,audit/types.ts,audit/auditHandler.tsnow useimport typefor theirreact-adminimports — these were alreadytype-only usages, but the explicit
typekeyword guarantees esbuilderases them at build time so the server bundle has no
require('react-admin').package.json:exportsmap for.(back-compat) and./serverwith.d.ts,ESM, and CJS targets for each.
tsupnow builds both entries.react-adminmoved topeerDependenciesMeta.optional = truesoserver-only consumers don't get install warnings.
build:checkscript that asserts the server bundle has noreact-adminreference.tests/serverBundle.test.ts— Jest guard that fails CI ifdist/server.{js,mjs}ever start referencing
react-adminagain./serversubpath.Non-breaking
The top-level entry is unchanged: it still re-exports both the
dataProviderand the handlers, so existing imports continue to workwithout modification.
Test plan
pnpm buildproducesdist/index.{js,mjs,d.ts}anddist/server.{js,mjs,d.ts}grep react-admin dist/server.*returns nothingpnpm testpasses (164/164, including the newserverBundle.test.ts)pnpm build:checkpassesfrom "ra-data-simple-prisma/server"in a Next.jsApp Router function on Vercel, confirm the function bundle no
longer traces
react-admin/react-router-dom