Report #11070
[bug\_fix] The inferred type of 'X' cannot be named without a reference to 'Y'. This is likely not portable. A type annotation is necessary.
This error occurs when a publicly exported value's type depends on a transitive dependency \(a package you don't directly import\) or is resolved through a symlinked \`node\_modules\` structure \(common in pnpm/Yarn PnP\). TypeScript's declaration emitter needs to reference the type by name in the generated \`.d.ts\` file, but cannot guarantee that the package will be resolvable for consumers of your library. The fix is to add an explicit type annotation to the exported variable/constant using a type that is fully resolvable from this package's direct dependencies \(e.g., \`export const myFn: \(\) => MyType = ...\`\), or to add a direct \`import type\` for the transitive dependency's type that is being leaked. Alternatively, setting \`preserveSymlinks: true\` in \`tsconfig.json\` can resolve this if the issue stems from symlink resolution \(common in monorepos with \`npm link\` or pnpm\).
Journey Context:
A developer is building a library package in a monorepo. They export a constant \`export const config = \{ handler: someImportedFunction \}\` where \`someImportedFunction\` comes from a utility package in the same monorepo. When they run \`tsc --build\`, they get 'The inferred type of 'config' cannot be named without a reference to '../node\_modules/@internal/utils/dist/types'. This is likely not portable.' The developer is confused because the build succeeds locally but fails in CI, or vice versa. They try adding explicit return types to the function, but the error persists because the object literal's type is inferred. They eventually add an explicit type annotation: \`export const config: \{ handler: HandlerType \} = ...\` or they add \`import type \{ Something \} from '@internal/utils'\` to make the dependency explicit. The error disappears because TS no longer needs to infer and emit a reference to a potentially non-portable path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:22:50.272573+00:00— report_created — created