build(nextjs): ship a complete CommonJS build - #554
Open
DonOmalVindula wants to merge 1 commit into
Open
Conversation
esbuild ran unbundled on three entry files only, so dist/cjs contained just
those three and `require('@asgardeo/nextjs')` failed with "Cannot find module
'./AsgardeoNextClient'". The ESM output only worked because `tsc` re-emitted
every file into dist/esm afterwards.
- Transpile every source file (tests excluded) for both formats; a bundle
cannot keep the per-module 'use client' / 'use server' directives, which
esbuild preserves in unbundled output.
- Write dist/cjs/package.json with "type": "commonjs" so Node does not parse
the CommonJS files as ESM under the package's "type": "module".
- Let tsc emit declarations only.
- Mark the type-only re-exports of the client entry with `export type`, since
esbuild cannot elide them per file.
- Fix the package's `types`, `homepage` and `repository` paths.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 41 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🦋 Changeset detectedThe changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. |
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.
Problem
esbuild.config.mjsran withbundle: falseon three entry points, sodist/cjscontained onlyindex.js,server/index.jsandmiddleware.js, each requiring files that do not exist:The ESM build only worked because the build script then ran
tsc --outDir dist/esm, which re-emitted every file on top of esbuild's output. Anything resolving therequirecondition (Jest, CommonJS tooling) got the broken tree. On top of that the package is"type": "module", so Node parsesdist/cjs/*.jsas ESM, and the top-leveltypesfield pointed atdist/index.d.ts, which does not exist.Fix
srctree. This package cannot be bundled like its siblings: Next.js needs'use client'/'use server'on the module that defines each component or server action, and esbuild keeps those directives in unbundled output (verified: 19use clientand 23use serverfiles insrc,dist/esmanddist/cjs).dist/cjs/package.jsonwith"type": "commonjs"is written by the build.tscnow emits declarations only (--emitDeclarationOnly, intodist/typesas before).src/client/index.tsare markedexport type; esbuild cannot elide them per file, so they would otherwise become runtime re-exports of names that do not exist.types,homepageandrepository.directoryinpackage.jsonpoint at the right paths.Testing
pnpm build: 62 files in each ofdist/esmanddist/cjs, no straytscJavaScript, declarations indist/types.require('@asgardeo/nextjs/middleware')loads and exposesasgardeoMiddlewareandcreateRouteMatcher.require('@asgardeo/nextjs')andrequire('@asgardeo/nextjs/server')now get past this package but stop in@asgardeo/browser's CommonJS bundle, which begins withimport {Buffer} from 'buffer/index.js'(and the sibling packages'dist/cjsalso lack a"type": "commonjs"package.json). Those are pre-existing issues in the other packages and are left for a separate PR.pnpm lint,pnpm vitest runandtsc --noEmitfor@asgardeo/nextjspass.Changeset included (
@asgardeo/nextjspatch).🤖 Generated with Claude Code