diff --git a/tsc/testdata/fixtures/compiler/checker.ts b/tsc/testdata/fixtures/compiler/checker.ts index 0567712f11da3..35d9e2b5e5c5b 100644 --- a/tsc/testdata/fixtures/compiler/checker.ts +++ b/tsc/testdata/fixtures/compiler/checker.ts @@ -34064,6 +34064,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!runtimeImportSpecifier) { return undefined; } + + // Check if the file is a script (not a module) - scripts can't use automatic JSX runtime + if (file && !isExternalOrCommonJsModule(file)) { + error(location, Diagnostics.JSX_cannot_be_used_in_a_script_file_when_using_automatic_JSX_runtime_jsx_react_jsx_or_react_jsxdev_Add_export_to_make_this_a_module_or_use_a_module_file); + if (links) { + links.jsxImplicitImportContainer = false; + } + return undefined; + } + const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic; const errorMessage = isClassic ? Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option diff --git a/tsc/testdata/fixtures/compiler/diagnosticMessages.json b/tsc/testdata/fixtures/compiler/diagnosticMessages.json index 17586e927d0ac..2280981bad4b3 100644 --- a/tsc/testdata/fixtures/compiler/diagnosticMessages.json +++ b/tsc/testdata/fixtures/compiler/diagnosticMessages.json @@ -919,6 +919,10 @@ "category": "Error", "code": 1280 }, + "JSX cannot be used in a script file when using automatic JSX runtime (jsx: 'react-jsx' or 'react-jsxdev'). Add 'export {}' to make this a module, or use a module file.": { + "category": "Error", + "code": 1281 + }, "Cannot access '{0}' from another file without qualification when '{1}' is enabled. Use '{2}' instead.": { "category": "Error", "code": 1281