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.

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
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

2 participants