Skip to content

Fix broken package imports; ship CommonJS, clean build (0.2.1)#2

Merged
Birua merged 1 commit into
developfrom
fix/cjs-build-and-casing-0.2.1
Jun 16, 2026
Merged

Fix broken package imports; ship CommonJS, clean build (0.2.1)#2
Birua merged 1 commit into
developfrom
fix/cjs-build-and-casing-0.2.1

Conversation

@Birua

@Birua Birua commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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.

# Problem Symptom Fix
1 tsc emitted ESM (module: ESNext) but package.json had no "type": "module" require()SyntaxError: Unexpected token 'export'; native ESM import also failed. Only bundlers hid it. tsconfig module: CommonJS
2 export { default as IncentivSigner }__importDefault(...).default getter the CJS export-lexer can't see import { IncentivSigner }Named export 'IncentivSigner' not found under native ESM Export the class by name + re-export by name (default kept for back-compat)
3 Stale dist on a case-insensitive build host shipped contracts/EntryPoint.js (capital E) + orphaned Typechain files works on macOS/Windows, module-not-found on Linux (./contracts/entryPoint) clean script; build: npm run clean && tsc

Why 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 → native require('@incentiv/dapp-sdk') returns IncentivEnvironment, IncentivResolver, IncentivSigner
  • Native ESM import { IncentivSigner, IncentivResolver, IncentivEnvironment } resolves
  • Tarball contracts/ contains only lowercase entryPoint.js; no EntryPoint.js / EntryPoint__factory.js / common.js orphans
  • tsc --noEmit clean; full vitest suite green

Also included

New tests/IncentivResolver.test.ts covering the connect popup/postMessage flow (resolve/reject/popup-blocked/popup-closed, origin + source spoof guards, SSR guard).

Notes

  • 0.2.1 is not yet published — publish after merge.
  • The package still exposes a top-level default export of IncentivSigner (back-compat); the public named API is unchanged.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clean script and run it before tsc to prevent stale/mis-cased dist artifacts from being shipped.
  • Export IncentivSigner as 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, but src/index.ts currently only re-exports named symbols and does not export a default. This makes import 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.

@Birua
Birua merged commit cbca7b2 into develop Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants