From 983250fefc38dcc7cab7a22905bde138820c6029 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 16:49:56 +0000 Subject: [PATCH] Fix error message to show 'Fragment' instead of 'React' for react-jsx modes Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com> --- src/compiler/checker.ts | 6 ++- ...FactoryReference(jsx=react-jsx).errors.txt | 4 +- ...toryReference(jsx=react-jsxdev).errors.txt | 4 +- ...formCustomImport(jsx=react-jsx).errors.txt | 4 +- ...mCustomImport(jsx=react-jsxdev).errors.txt | 4 +- ...stomImportPragma(jsx=react-jsx).errors.txt | 4 +- ...mImportPragma(jsx=react-jsxdev).errors.txt | 4 +- ...jsxRuntimePragma(jsx=react-jsx).errors.txt | 41 +++++++++++++++++++ ...RuntimePragma(jsx=react-jsxdev).errors.txt | 41 +++++++++++++++++++ 9 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 tests/baselines/reference/jsxRuntimePragma(jsx=react-jsx).errors.txt create mode 100644 tests/baselines/reference/jsxRuntimePragma(jsx=react-jsxdev).errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f3cf9c10ff3..2e9751bf24a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37441,11 +37441,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!shouldResolveFactoryReference) return sourceFileLinks.jsxFragmentType = anyType; const shouldModuleRefErr = compilerOptions.jsx !== JsxEmit.Preserve && compilerOptions.jsx !== JsxEmit.ReactNative; + // When using react-jsx/react-jsxdev, the fragment comes from the jsx-runtime module as "Fragment" export + // Use "Fragment" in error message instead of the default "React" namespace + const isModernJsx = compilerOptions.jsx === JsxEmit.ReactJSX || compilerOptions.jsx === JsxEmit.ReactJSXDev; + const fragmentFactoryNameForError = isModernJsx ? ReactNames.Fragment : jsxFragmentFactoryName; const jsxFactoryRefErr = diagnostics ? Diagnostics.Using_JSX_fragments_requires_fragment_factory_0_to_be_in_scope_but_it_could_not_be_found : undefined; const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ?? resolveName( node, - jsxFragmentFactoryName, + fragmentFactoryNameForError, shouldModuleRefErr ? SymbolFlags.Value : SymbolFlags.Value & ~SymbolFlags.Enum, /*nameNotFoundMessage*/ jsxFactoryRefErr, /*isUse*/ true, diff --git a/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsx).errors.txt b/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsx).errors.txt index c8caaefa362..97b1dd60a77 100644 --- a/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsx).errors.txt +++ b/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsx).errors.txt @@ -1,5 +1,5 @@ jsxFragmentFactoryReference.tsx(3,9): error TS2875: 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. -jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ==== jsxFragmentFactoryReference.tsx (2 errors) ==== @@ -9,7 +9,7 @@ jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires ~~ !!! error TS2875: 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. ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ) } \ No newline at end of file diff --git a/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsxdev).errors.txt b/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsxdev).errors.txt index 16bb6f5a544..400aa3bd175 100644 --- a/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsxdev).errors.txt +++ b/tests/baselines/reference/jsxFragmentFactoryReference(jsx=react-jsxdev).errors.txt @@ -1,5 +1,5 @@ jsxFragmentFactoryReference.tsx(3,9): error TS2875: This JSX tag requires the module path 'react/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. -jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ==== jsxFragmentFactoryReference.tsx (2 errors) ==== @@ -9,7 +9,7 @@ jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires ~~ !!! error TS2875: This JSX tag requires the module path 'react/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ) } \ No newline at end of file diff --git a/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsx).errors.txt b/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsx).errors.txt index 2b8fbaf4e46..2b1ec10df02 100644 --- a/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsx).errors.txt +++ b/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsx).errors.txt @@ -1,5 +1,5 @@ jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. -jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ==== jsxJsxsCjsTransformCustomImport.tsx (2 errors) ==== @@ -8,7 +8,7 @@ jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments req ~~ !!! error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found.

text
diff --git a/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).errors.txt b/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).errors.txt index 31af5093deb..062df44ff80 100644 --- a/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).errors.txt +++ b/tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).errors.txt @@ -1,5 +1,5 @@ jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. -jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ==== jsxJsxsCjsTransformCustomImport.tsx (2 errors) ==== @@ -8,7 +8,7 @@ jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments req ~~ !!! error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found.

text
diff --git a/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt b/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt index 7155c43a5da..61276f782e4 100644 --- a/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt +++ b/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt @@ -1,5 +1,5 @@ preact.tsx(3,11): error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. -preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ==== react.tsx (0 errors) ==== @@ -20,7 +20,7 @@ preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'R ~~ !!! error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found.

text
diff --git a/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).errors.txt b/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).errors.txt index ad4bb3c20b1..3a1dfd23eb3 100644 --- a/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).errors.txt +++ b/tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).errors.txt @@ -1,5 +1,5 @@ preact.tsx(3,11): error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. -preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. ==== react.tsx (0 errors) ==== @@ -20,7 +20,7 @@ preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'R ~~ !!! error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed. ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found.

text
diff --git a/tests/baselines/reference/jsxRuntimePragma(jsx=react-jsx).errors.txt b/tests/baselines/reference/jsxRuntimePragma(jsx=react-jsx).errors.txt new file mode 100644 index 00000000000..988e3e9d679 --- /dev/null +++ b/tests/baselines/reference/jsxRuntimePragma(jsx=react-jsx).errors.txt @@ -0,0 +1,41 @@ +four.tsx(6,21): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. +one.tsx(5,21): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. + + +==== one.tsx (1 errors) ==== + /// + /* @jsxRuntime classic */ + import * as React from "react"; + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + ~~ +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. + export const selfClosing = ; +==== two.tsx (0 errors) ==== + /// + /* @jsxRuntime automatic */ + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + export const selfClosing = ; +==== three.tsx (0 errors) ==== + /// + /* @jsxRuntime classic */ + /* @jsxRuntime automatic */ + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + export const selfClosing = ; +==== four.tsx (1 errors) ==== + /// + /* @jsxRuntime automatic */ + /* @jsxRuntime classic */ + import * as React from "react"; + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + ~~ +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. + export const selfClosing = ; +==== index.ts (0 errors) ==== + export * as one from "./one.js"; + export * as two from "./two.js"; + export * as three from "./three.js"; + export * as four from "./four.js"; \ No newline at end of file diff --git a/tests/baselines/reference/jsxRuntimePragma(jsx=react-jsxdev).errors.txt b/tests/baselines/reference/jsxRuntimePragma(jsx=react-jsxdev).errors.txt new file mode 100644 index 00000000000..988e3e9d679 --- /dev/null +++ b/tests/baselines/reference/jsxRuntimePragma(jsx=react-jsxdev).errors.txt @@ -0,0 +1,41 @@ +four.tsx(6,21): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. +one.tsx(5,21): error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. + + +==== one.tsx (1 errors) ==== + /// + /* @jsxRuntime classic */ + import * as React from "react"; + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + ~~ +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. + export const selfClosing = ; +==== two.tsx (0 errors) ==== + /// + /* @jsxRuntime automatic */ + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + export const selfClosing = ; +==== three.tsx (0 errors) ==== + /// + /* @jsxRuntime classic */ + /* @jsxRuntime automatic */ + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + export const selfClosing = ; +==== four.tsx (1 errors) ==== + /// + /* @jsxRuntime automatic */ + /* @jsxRuntime classic */ + import * as React from "react"; + export const HelloWorld = () =>

Hello world

; + export const frag = <>
; + ~~ +!!! error TS2879: Using JSX fragments requires fragment factory 'Fragment' to be in scope, but it could not be found. + export const selfClosing = ; +==== index.ts (0 errors) ==== + export * as one from "./one.js"; + export * as two from "./two.js"; + export * as three from "./three.js"; + export * as four from "./four.js"; \ No newline at end of file