Skip to content

Since 5.7.2: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.Β #60603

Closed
@RobertSandiford

Description

@RobertSandiford

πŸ”Ž Search Terms

Search/Keywords: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.

πŸ•— Version & Regression Information

Since 5.7.2. No 5.7.0 or 5.7.1 available. OK in 5.6.3

⏯ Playground Link

Best effort Playground

πŸ’» Code

    <>
        <h1>Logged Out</h1>
    </>

πŸ™ Actual behavior

Since TS 5.7.2 JSX Fragments are no longer accepted.

Compile error: error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.

πŸ™‚ Expected behavior

JSX Fragments should continue to work

Additional information about the issue

I have a custom JSX setup, I'm not using React. babel-preset-react is used to transform JSX. This grabs Fragment from the JSX runtime provided and passes this as the node type when creating the element via the JSX runtime. It has been working since TS 4 until now.

Compiled output:

import { jsx as _jsx, Fragment as _Fragment } from "tungsten/jsxRuntime.js";
...
    _jsx(_Fragment, {
        children: _jsx("h1", {
            children: "Logged Out"
        })
    })

The error message about React is odd, JSX and React are independent, why would React anything be needed to use JSX fragments? babel-preset-react with runtime: "automatic" loads jsx functions and the Fragment constant from a specified JSX runtime and does not rely on anything called React.

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions