Skip to content

fix: improve error message for JSX in non-module files (Issue #64438) - #64616

Open
Om Dandagvhal (OMD-123) wants to merge 1 commit into
microsoft:mainfrom
OMD-123:fix-jsx-non-module-error
Open

Om Dandagvhal (OMD-123) wants to merge 1 commit into
microsoft:mainfrom
OMD-123:fix-jsx-non-module-error

Conversation

@OMD-123

Copy link
Copy Markdown

Summary

Fixes #64438

The Problem

When a file uses JSX but is not an external module (no imports/exports), TypeScript shows the confusing error:

"This JSX tag requires the module path 'react/jsx-runtime' to exist but none could be found. Make sure you have types for the appropriate package installed."

This is misleading because the file cannot import modules at all - it's a script, not a module. The real issue is that JSX requires the automatic runtime which imports from , but non-module files can't import anything.

The Fix

Added a check in to return early if the file is not an external module (). This allows the existing, more appropriate error (TS7026: "JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists") to surface as the primary diagnostic.

Expected Behavior After Fix

For a file like:

Before: Confusing "module path react/jsx-runtime could not be found" error
After: Clear "JSX element implicitly has type 'any'" error (TS7026) - which correctly indicates the file needs to be a module or have JSX types configured.

…ft#64438)

When a file uses JSX but is not an external module (no imports/exports),
the error message 'This JSX tag requires the module path X to exist...'
is confusing because the file cannot import modules at all.

The fix checks if the file is an external module before attempting to
resolve the JSX runtime import. If not, it returns nil early, which
allows the existing 'JSX element implicitly has type any' error (7026)
to surface as the primary diagnostic.

This matches the expected behavior described in the issue where the
real issue is 'scripts can't import modules'.
Copilot AI balanced review requested due to automatic review settings October 3, 2026 07:14
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The early return can hide missing runtime imports and disable runtime-provided JSX types, and lacks regression coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Improves JSX diagnostics for non-module files by skipping implicit runtime resolution.

Changes:

  • Detects source files without an external-module indicator.
  • Suppresses JSX runtime resolution for those files.
File Description
tsc/​internal/​checker/​jsx.go Adds the non-module early return.

Comment on lines +1455 to +1457
// If the file is not an external module (no imports/exports), it cannot import the JSX runtime.
// Return nil to avoid the confusing "module path ... could not be found" error (Issue #64438).
if file.ExternalModuleIndicator == nil {

This branch has not been deployed

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Incorrect/unhelpful error message for non-module jsx file

2 participants