AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next.Js TypeScript Plugin Diagnostics Not Reported By CLI / CI Type Checking

Next.js provides a TypeScript language-service plugin that reports framework-specific diagnostics in the editor, but these diagnostics are not available when running `tsc` or any Next.js CLI command. This means CI type checking can miss Next.js-specific type errors (e.g., invalid metadata export types), leading to false confidence. A framework-aware CLI type check command (e.g., `next check`) should be added.

highConfidence 92%Next.jsAffected V16.3.1-Canary.13

Origin Analysis

The Next.js TypeScript plugin is implemented as a language-service plugin, which is only loaded by editors (VS Code) that support TypeScript plugin loading. The TypeScript compiler (`tsc`) does not support loading language-service plugins (see microsoft/TypeScript#16607), and Next.js does not provide a wrapper CLI command that uses the TypeScript LanguageService API to load its plugin and emit diagnostics. Therefore, Next.js-specific diagnostics are invisible to command-line/CI type checking.
1. Create a Next.js project with the `next` TypeScript plugin enabled in tsconfig.json (e.g., `"plugins": [{ "name": "next" }]`). 2. Write a page that exports a `metadata` object with an incorrect type (e.g., string instead of Metadata). 3. Observe the diagnostic in VS Code (ts(71008)). 4. Run `pnpm tsc` or `next build`; no error is reported. 5. Run `pnpm next check` or `pnpm next tsc`; the command does not exist (or is misinterpreted as project directory).

Fixing Code Block

Edge Case Audit

This fix relies on the internal API of the Next.js TypeScript plugin and the 'next/typescript' export, which may change across Next.js versions. Running the LanguageService manually can be slower than `tsc` because it does not leverage incremental compilation caches. It may also load a different TypeScript version than the one used by the project, causing compatibility issues; ensure the script uses the project's installed TypeScript (via `require('typescript')`) or bundle a compatible version. If the plugin's `create` function expects a different shape of the language service host, the service may fail or produce incomplete diagnostics. Rollback is straightforward: remove the script and revert to `tsc`, but be aware that Next.js-specific diagnostics will again be missed. For production, prefer an official Next.js implementation that is properly tested across platforms and TypeScript versions.

Ecosystem Topology