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.
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 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: truein libraries- Complex inferred return types
- Missing type imports
⚡ Quick fix
- Annotate the export:
export const x: SomeType = ... - Import the type explicitly
- Install/import the dependency providing the type directly (pnpm)
Detailed fix by platform
TypeScript
import type { Router } from "express"; export const router: Router = createRouter();
How to diagnose
- Declaration — Enabled?
- Type — Nameable?
- 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:
Similar errors
- Cannot find module './App.vue' or its corresponding type declarations TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
- TS1005: ';' expected / ',' expected (syntax error) TypeScript: error TS1005: ';' expected.
- TS1128: Declaration or statement expected TypeScript: error TS1128: Declaration or statement expected.
Most viewed in TypeScript
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026