Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gatsby minimal TS starter generates code with deprecated React import #38869

Open
2 tasks done
c-vetter opened this issue Feb 24, 2024 · 0 comments
Open
2 tasks done

Gatsby minimal TS starter generates code with deprecated React import #38869

c-vetter opened this issue Feb 24, 2024 · 0 comments
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@c-vetter
Copy link

Preliminary Checks

Description

Hello 🙂
Testing Gatsby today, I immediately got stumped when I opened src/pages/index.tsx on account of the React import there.

Direct React imports have been obsolete since the new jsx transform arrived in 2020. The namespace import style in src/pages/index.tsx has been deprecated even before that.

Connected to those imports is the jsx setting for TypeScript, which should now be "react-jsx".

While this is easily fixed on my end, this should not be yielded from your starters.

Apart from just being old stuff, this encourages a code style that makes reading the code more onerous.

I will look into providing PRs to fix, if and when I decide to go further with Gatsby.

Reproduction Link

https://stackblitz.com/github/gatsbyjs/gatsby-starter-minimal-ts?file=src%2Fpages%2Findex.tsx

Steps to Reproduce

  1. npm init gatsby bug -- -y -ts
  2. open bug/tsconfig.json and bug/src/pages/index.tsx in an editor

Expected Result

index.tsx should have neither an import * as React from "react" nor an import React from "react", both of which are deprecated and obsolete.
Also, there should be no issues when removing such an obsolete import.

tsconfig.json should have compilerOptions.jsx set to "react-jsx".

Actual Result

index.tsx starts with import * as React from "react", and when removing this line, TypeScript raises this error for all JSX tags:

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead. ts(2686)

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 20.11.1 - ~\scoop\apps\nvm\current\nodejs\nodejs\node.EXE
    Yarn: 1.22.19 - ~\scoop\apps\yarn\current\bin\yarn.CMD
    npm: 10.2.4 - ~\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD
  Languages:
    Python: 3.12.2
  Browsers:
    Edge: Chromium (121.0.2277.128)
  npmPackages:
    gatsby: ^5.13.3 => 5.13.3 
    gatsby-plugin-emotion: ^8.13.1 => 8.13.1 
    gatsby-plugin-manifest: ^5.13.1 => 5.13.1

Config Flags

No response

@c-vetter c-vetter added the type: bug An issue or pull request relating to a bug in Gatsby label Feb 24, 2024
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant