Skip to content

usernamer: usernamer/ko resolves to a UMD bundle under "type": "module", and types paths do not match emitted .d.ts files #26

Open

Description

@trackoor

In packages/usernamer, importing usernamer/ko fails at runtime in Node.js because exports["./ko"].default points to a UMD bundle loaded as ESM, and TypeScript cannot find declarations for either usernamer or usernamer/ko because the types paths in package.json do not match the emitted .d.ts paths.

// repro.mjs
import { encode, decode } from "usernamer/ko";
console.log(encode(100), decode("귀여운 알파카"));
// repro.mts
import { encode } from "usernamer";
import { encode as encodeKo } from "usernamer/ko";
console.log(encode(0), encodeKo(0));

Run:

npm i usernamer@1.0.0 typescript@5.9.3
node repro.mjs
npx tsc --strict --module nodenext --noEmit repro.mts

Actual output from node repro.mjs:

file:///.../repro.mjs:1
import { encode, decode } from "usernamer/ko";
                 ^^^^^^
SyntaxError: The requested module 'usernamer/ko' does not provide an export named 'decode'

(import * as ko from "usernamer/ko" and require("usernamer/ko") also fail with ReferenceError: self is not defined.)

Actual output from npx tsc --strict --module nodenext --noEmit repro.mts (also reproduces with --module preserve --moduleResolution bundler):

repro.mts(1,24): error TS7016: Could not find a declaration file for module 'usernamer'. '/.../node_modules/usernamer/dist/index.modern.js' implicitly has an 'any' type.
repro.mts(2,36): error TS7016: Could not find a declaration file for module 'usernamer/ko'. '/.../node_modules/usernamer/dist/ko/usernamer.js' implicitly has an 'any' type.

Expected:

node repro.mjs prints 귀여운 알파카 100, and tsc succeeds without errors.

Versions tested:

  • usernamer: 1.0.0 (npm latest) and main (53994cc1)
  • Node.js: v26.13.0
  • TypeScript: 5.9.3 and 7.0.2

In packages/usernamer/package.json, microbundle src/ko.ts -o dist/ko --no-pkg-main writes all output formats to dist/ko/usernamer.js leaving the UMD bundle in a "type": "module" package, and the chained microbundle runs emit declarations at dist/src/src/src/*.d.ts while types and exports.*.types point to dist/src/src/*.d.ts.

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions