TS4023/TS2742: exported variable has or is using name from external module but cannot be named TypeScript Origin: On your device OSI layer 7 · Application Last updated 5 Nov 2026

TypeScript: error TS4023: Exported variable 'x' has or is using name 'Foo' from external module "..." but cannot be named. / TS2742: The inferred type cannot be named without a reference

With declaration: true, TypeScript can't write the inferred type into .d.ts because it refers to a type it can't import by name.

Exact message you may see error TS4023: Exported variable 'x' has or is using name 'Foo' from external module but cannot be named.error TS2742: The inferred type of 'x' cannot be named without a reference to '.pnpm/...'. This is likely not portable. A type annotation is necessary.TS4023 TS2742 cannot be named without a referenceerror TS4058: Return type of exported function has or is using name from external module but cannot be named
Seen on: TypeScript npm

Meaning

Add an explicit type annotation, import the needed type (so it's nameable), or export it. TS2742 (pnpm/monorepo) means the inferred type references a nested node_modules path — add an explicit annotation or a direct dependency/import of that package's type.

Common causes

  • Exported value's inferred type uses a non-exported/transitive type
  • pnpm nested node_modules paths (TS2742)
  • declaration: true in libraries
  • Complex inferred return types
  • Missing type imports

⚡ Quick fix

  1. Annotate the export: export const x: SomeType = ...
  2. Import the type explicitly
  3. Install/import the dependency providing the type directly (pnpm)

Detailed fix by platform

TypeScript

  1. import type { Router } from "express"; export const router: Router = createRouter();

How to diagnose

  1. Declaration — Enabled?
  2. Type — Nameable?
  3. pnpm — Nested path?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Cannot find module './App.vue' or its corresponding type declarations — TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations. (Vue)Cannot find module '.…TS1005: ';' expected / ',' expected (syntax error) — TypeScript: error TS1005: ';' expected. (TypeScript)TS1005: ';' expected …TS1128: Declaration or statement expected — TypeScript: error TS1128: Declaration or statement expected. (TypeScript)TS1128: Declaration o…TS2300: Duplicate identifier — TypeScript: error TS2300: Duplicate identifier 'Foo'. (TypeScript)TS2300: Duplicate ide…TS2307 — TS2307: Cannot find module 'x' or its corresponding type declarations. (Node.js)TS2307TS2403: Subsequent variable declarations must have the same type — TypeScript: error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'number'. (TypeScript)TS2403: Subsequent va…TS2502/TS7022: referenced directly or indirectly in its own initializer — TypeScript: error TS7022: 'x' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer (TypeScript)TS2502/TS7022: refere…TS2589: Type instantiation is excessively deep and possibly infinite — TypeScript: error TS2589: Type instantiation is excessively deep and possibly infinite. (TypeScript)TS2589: Type instanti…TS4023/TS…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.