Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

TypeScript projects targeting ES modules (module: "nodenext") fail to compile with error TS1203 because index.d.ts uses CommonJS export = cuid2 syntax, which is incompatible with ECMAScript modules.

Changes

  • Type declarations (index.d.ts): Replaced namespace declaration with export = with direct named exports for createId, init, getConstants, and isCuid

Before/After

// Before: CommonJS-style (TS1203 error with ES modules)
declare namespace cuid2 {
  export function createId(): string;
  export function init(options?: {...}): () => string;
  export function getConstants(): {...};
  export function isCuid(id: string, options?: {...}): boolean;
}
export = cuid2;

// After: ES module-style
export function createId(): string;
export function init(options?: {...}): () => string;
export function getConstants(): {...};
export function isCuid(id: string, options?: {...}): boolean;

Users can continue importing via named imports (import { createId } from '@paralleldrive/cuid2') or namespace imports (import * as cuid2 from '@paralleldrive/cuid2'). No runtime code changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>TypeScript Error: TS1203 with export = when targeting ES Modules</issue_title>
<issue_description>I encountered a build error (TS1203) when trying to compile a TypeScript project that uses @paralleldrive/cuid2. This error occurs because the library uses an export = assignment in its declaration file (index.d.ts), which is incompatible with projects targeting modern ECMAScript modules (ESM).

Error Output

node_modules/.bun/@paralleldrive+cuid2@3.0.4/node_modules/@paralleldrive/cuid2/index.d.ts:22:1 - error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.

22 export = cuid2;
   ~~~~~~~~~~~~~~~

Steps to Reproduce

  1. Set up a new TypeScript project.
  2. Ensure tsconfig.json is configured to target ES Modules (e.g., "module": "nodenext").
  3. Install the package: npm install @paralleldrive/cuid2.
  4. Import the package in a TypeScript file:
    import { createId } from '@paralleldrive/cuid2';
  5. Attempt to compile the project using npx tsc -b.

Potential Fix

To resolve this for users targeting ES Modules, consider replacing the export = cuid2; line in the declaration file with the more modern and compatible export default cuid2; format.

This change would allow projects using modern module configurations to build without requiring them to set skipLibCheck: true in their tsconfig.json.

Environment

  • Package Version: @paralleldrive/cuid2@3.0.4
  • TypeScript Version: 5.9.3
  • Node.js: 24.11.1
  • Relevant tsconfig.json settings:
    {
      "compilerOptions": {
        "target": "es2024",
        "module": "nodenext",
      }
    }
    ```</issue_description>
    

<agent_instructions>Could you take a look, validate, and fix if required? Please ensure that typescript runs without error prior to PR.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Note

Modernizes the type declarations for ESM compatibility and fixes TS1203.

  • Replace namespace + export = with top-level named exports for createId, init, getConstants, and isCuid in index.d.ts
  • No runtime changes; public API shape via named imports remains the same

Written by Cursor Bugbot for commit a910d6e. This will update automatically on new commits. Configure here.

Co-authored-by: ericelliott <364727+ericelliott@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TS1203 error with cuid2 library in TypeScript project Fix TS1203: Replace CommonJS export with ES module exports in type declarations Jan 5, 2026
Copilot AI requested a review from ericelliott January 5, 2026 21:17
@ericelliott
Copy link
Collaborator

@cursoragent please /review and be sure to test the import in your sandbox to make sure it works with the typescript compiler

@cursor
Copy link

cursor bot commented Jan 25, 2026

Review Complete ✅

I've thoroughly reviewed and tested the TypeScript TS1203 fix. Here's what I validated:

Type Declaration Changes

The index.d.ts file correctly uses ES module exports instead of the incompatible CommonJS export = syntax. All function signatures are properly typed and match the runtime implementation.

TypeScript Compilation Tests

  • ✅ Compiles successfully with module: "nodenext" (the configuration that triggered TS1203)
  • ✅ No TS1203 errors when targeting ES modules
  • ✅ Type declarations are syntactically correct

Import Pattern Validation

Tested and verified both import patterns work correctly:

// Named imports
import { createId, init, getConstants, isCuid } from '@paralleldrive/cuid2';

// Namespace imports
import * as cuid2 from '@paralleldrive/cuid2';

Runtime Verification

Created and ran comprehensive runtime tests confirming:

  • All four exported functions work correctly
  • Function signatures match type declarations
  • Optional parameters behave as expected
  • Both import patterns produce identical results

Quality Assurance

  • ✅ All existing unit tests pass (23/23 tests)
  • ✅ CLI tests pass (10/10 tests)
  • ✅ Lint checks pass
  • ✅ No breaking changes introduced
  • ✅ Backward compatible with existing usage

The fix is production-ready and resolves the reported issue while maintaining full compatibility with existing code.

Open in Cursor Open in Web

cursoragent and others added 2 commits January 25, 2026 18:35
- Validated ES module type declarations work with module: nodenext
- Tested both named and namespace import patterns
- Verified runtime behavior matches type declarations
- Confirmed backward compatibility maintained
@ericelliott ericelliott marked this pull request as ready for review January 25, 2026 18:38
@ericelliott ericelliott merged commit 3bec9b1 into main Jan 25, 2026
1 check passed
@ericelliott ericelliott deleted the copilot/fix-typescript-error-ts1203 branch January 25, 2026 19:01
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.

TypeScript Error: TS1203 with export = when targeting ES Modules

3 participants