tanem / react-svg

:art: A React component that injects SVG into the DOM.

Home Page:https://npm.im/react-svg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Namespace 'React' has no exported member 'JSX'.

ahoys opened this issue · comments

So, I'm having issues using react-svg in my React component library. The main culprit is that in ReactSVG.d.ts there are some definitions that are no longer valid with the newer React versions. Please see the error below:

image

Current broken implementation:

image

Likely fix:

image

"react": "^18.1.0",
"react-dom": "^18.1.0",
"typescript": "^5.1.6",

How to reproduce?

In a React project, install fresh React / Typescript versions as seen above. Add the following build script and run it yarn build

  "scripts": {
    "build": "tsc"
  },

Hey @ahoys 👋 I can't seem to recreate this issue.

I expect I'd see a compilation issue like that before publishing anything. The TS Live Example looks to be intact too. Also when I manually inspect the source code for @types/react v18.2.17 I can see the JSX namespace there.

What do you see if you run yarn why @types/react in your project that's consuming this library? Wondering if an older @types/react version is in the tree somewhere and is actually the one being referenced.

I'm currently forced to use the following @types/react as updating breaks some other libraries (styled-components):

$ yarn why @types/react
yarn why v1.22.15
[1/4] Why do we have the module "@types/react"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "@types/react@18.0.25"
info Has been hoisted to "@types/react"
info Reasons this module exists
   - Specified in "devDependencies"
   - Hoisted from "@types#draft-js#@types#react"
   - Hoisted from "@types#react-dom#@types#react"
   - Hoisted from "@types#react-test-renderer#@types#react"
   - Hoisted from "@types#styled-components#@types#react"
   - Hoisted from "@types#draftjs-to-html#@types#draft-js#@types#react"
   - Hoisted from "@types#html-to-draftjs#@types#draft-js#@types#react"
   - Hoisted from "@types#styled-components#@types#hoist-non-react-statics#@types#react"
info Disk size without dependencies: "196KB"
info Disk size with unique dependencies: "1.37MB"
info Disk size with transitive dependencies: "1.37MB"
info Number of shared dependencies: 3
Done in 0.32s.

So, is the assumption that the support for JSX came with newer minor releases?

Yea. Looks like the JSX namespace was added to the React namespace here. After a bit of snooping around, I can see that change was published in v18.2.6.