Fix broken package imports; ship CommonJS, clean build (0.2.1)#2
Merged
Conversation
The published 0.2.0 artifact could not be loaded by native Node consumers
and broke on case-sensitive filesystems. Three distinct problems:
1. ESM syntax with no "type": "module" — tsc emitted import/export
(module: ESNext) but package.json declared no module type, so
`require()` threw "Unexpected token 'export'" and native ESM import
failed too. Only bundlers (Vite/webpack) hid this. Switch tsc output
to CommonJS so require(), bundlers, and ESM interop all work.
2. `export { default as IncentivSigner }` compiled to an
__importDefault(...).default getter that Node's CJS export lexer can't
detect, so `import { IncentivSigner }` failed under native ESM. Export
the class by name and re-export it by name; default export kept for
back-compat.
3. Stale dist + case-insensitive build host left contracts/EntryPoint.js
(capital E) plus orphaned Typechain files in the tarball, while the
source imports "./contracts/entryPoint" (lowercase) — works on
macOS/Windows, fails on Linux/CI. Add a clean step so build wipes dist
first (`clean` script + `build: npm run clean && tsc`).
Also adds IncentivResolver unit tests (connect popup/postMessage flow,
SSR guards, popup-blocked/closed, origin and source spoof guards).
Verified against the packed tarball: native require() and ESM named
import both resolve IncentivSigner/IncentivResolver/IncentivEnvironment;
contracts ships only lowercase entryPoint.js with no orphans.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses packaging/consumption issues in @incentiv/dapp-sdk that broke native Node consumers and case-sensitive environments by switching the compiled output to CommonJS, ensuring dist/ is cleaned before builds, and adjusting how IncentivSigner is exported to support native ESM named-import interop. It also adds a new vitest suite for the IncentivResolver.getAccountAddress() popup + postMessage flow.
Changes:
- Switch TypeScript emit from ESM to CommonJS to make the published artifact loadable via
require()(and avoid Node parsing ESM syntax as CJS). - Add a
cleanscript and run it beforetscto prevent stale/mis-caseddistartifacts from being shipped. - Export
IncentivSigneras a named export (and add tests covering resolver popup messaging behavior).
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Changes TS module output to CommonJS to fix Node consumption. |
| package.json | Bumps version to 0.2.1 and ensures clean builds by wiping dist/ before tsc. |
| src/index.ts | Updates entrypoint exports to use the named IncentivSigner export. |
| src/IncentivSigner.ts | Exports IncentivSigner as a named export (while keeping the module’s default export). |
| tests/IncentivResolver.test.ts | Adds Node-environment tests for the popup + postMessage connect flow and guardrails. |
Comments suppressed due to low confidence (1)
src/index.ts:6
- The PR description/notes state that the package still exposes a top-level default export of
IncentivSigner, butsrc/index.tscurrently only re-exports named symbols and does not export a default. This makesimport IncentivSigner from "@incentiv/dapp-sdk"(and similar default-import interop) impossible from the package entrypoint. Either update the PR description or re-add a default export from the entrypoint (without reintroducing the default-as-named export pattern).
IncentivSigner,
type IncentivSignerOptions,
type IncentivTransactionResponse,
type IncentivTransactionReceipt,
} from "./IncentivSigner";
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
The published 0.2.0 artifact can't be loaded by native Node consumers and breaks on case-sensitive filesystems (Linux/CI/Docker). This PR fixes three distinct import problems and bumps to 0.2.1.
tscemitted ESM (module: ESNext) butpackage.jsonhad no"type": "module"require()→SyntaxError: Unexpected token 'export'; native ESM import also failed. Only bundlers hid it.tsconfigmodule: CommonJSexport { default as IncentivSigner }→__importDefault(...).defaultgetter the CJS export-lexer can't seeimport { IncentivSigner }→Named export 'IncentivSigner' not foundunder native ESMdiston a case-insensitive build host shippedcontracts/EntryPoint.js(capital E) + orphaned Typechain files./contracts/entryPoint)cleanscript;build: npm run clean && tscWhy bundler users never noticed
Vite/webpack/Next transpile ESM and resolve extensionless + case-insensitive specifiers, so the React app worked.
require(), SSR, and Node scripts hit #1/#2 immediately; Linux CI hits #3.Verification (against the packed tarball)
npm pack→ install in a clean dir → nativerequire('@incentiv/dapp-sdk')returnsIncentivEnvironment, IncentivResolver, IncentivSignerimport { IncentivSigner, IncentivResolver, IncentivEnvironment }resolvescontracts/contains only lowercaseentryPoint.js; noEntryPoint.js/EntryPoint__factory.js/common.jsorphanstsc --noEmitclean; full vitest suite greenAlso included
New
tests/IncentivResolver.test.tscovering the connect popup/postMessageflow (resolve/reject/popup-blocked/popup-closed, origin + source spoof guards, SSR guard).Notes
0.2.1is not yet published — publish after merge.IncentivSigner(back-compat); the public named API is unchanged.🤖 Generated with Claude Code