GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Since 5.7.2: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found. · Issue #60603 · microsoft/TypeScript

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

New issue
Copy link
New issue
Copy link
Closed
#60687
Closed
Since 5.7.2: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.#60603
#60687
Copy link
Assignees
iisaduan
Labels
Needs InvestigationThis issue needs a team member to investigate its status.

Description

@RobertSandiford
RobertSandiford
opened on Nov 26, 2024
Issue body actions

🔎 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.

Reacted by Mads Erik Forberg, Jartreg, Arseniy Ivanov and Max Patiiuk

Activity

  1. Ryan Cavanaugh (RyanCavanaugh)
    added
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Nov 27, 2024
  2. Ryan Cavanaugh (RyanCavanaugh)
    assigned
    Isabel Duan (iisaduan)
    on Nov 27, 2024
  3. iisaduan commented on Nov 30, 2024

    @iisaduan
    Isabel Duan (iisaduan)
    on Nov 30, 2024
    Member
    More actions

    What JSX setting are you currently using in your tsconfig? The "requires React to be in scope" sounds like it could be hitting a default error message, so knowing your jsx setting would help me diagnose the issue

    Since you are using a custom setup, the fix might be to specify jsxFactoryFragment: null as in #60122

  4. RobertSandiford commented on Dec 1, 2024

    @RobertSandiford
    RobertSandiford
    on Dec 1, 2024
    Author
    More actions

    Isabel Duan (@iisaduan)

    What JSX setting are you currently using in your tsconfig? The "requires React to be in scope" sounds like it could be hitting a default error message, so knowing your jsx setting would help me diagnose the issue

    Since you are using a custom setup, the fix might be to specify jsxFactoryFragment: null as in #60122

    It's just "jsx": "preserve" as the JSX transform is a post-tsc build step.

    It seems to me that with "jsx": "preserve" TS should not care about any JSX factories (although there might be something I'm not aware of).

    I've tried "jsxFragmentFactory": null, but it makes no difference.

    Here is a new playground with "jsx": "preserve" set, this now matches what I see in my IDE: playground 2

    Thanks

    Reacted by Isabel Duan
  5. Isabel Duan (iisaduan)
    closed this as completedin #60687on Dec 9, 2024
  6. RobertSandiford commented on Dec 10, 2024

    @RobertSandiford
    RobertSandiford
    on Dec 10, 2024
    Author
    More actions

    Isabel Duan (@iisaduan) Thanks

    Reacted by Isabel Duan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @iisaduan
    Isabel Duan (iisaduan)

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.