react-portabletext icon indicating copy to clipboard operation
react-portabletext copied to clipboard

'React' is declared but its value is never read.

Open mckelveygreg opened this issue 1 year ago • 6 comments

I am having a hard time using this library as it seems like I'm not picking up the build js files, but rather typescript is using the source files and having opinions about them! My tsconfig.json has skipLibCheck: true. It seems that it is not finding the correct export? I get the above error just by running tsc --noEmit

Right now my solution is to patch comment out the React references so my project will build.

I pulled down the repo to check things out. It looks like the tsconfig could be updated with "jsx": "react-jsx" as with React 17+, you no longer need to ghost import React to handle jsx and they suggest moving away from it. After updating the react eslint extends with "plugin:react/jsx-runtime" and removing the react import, all seemed well...

Except I can't build because of linting errors in react-portable-text.tsx that exist on main...

Are there settings I need to adjust on my end or can I help put up PR once the build issues get resolved?

mckelveygreg avatar Aug 12 '22 19:08 mckelveygreg

Do you have a code sandbox that reproduces this situation?

swalker326 avatar Aug 21 '22 02:08 swalker326

My bad! I was able to repro this by turning the tsconfig option "noUnusedLocals": true. This is a setting I'd like to keep on...

Let me know if there is anything else I can do to this example to help!

https://stackblitz.com/edit/vitejs-vite-askzne?file=tsconfig.json

mckelveygreg avatar Aug 21 '22 04:08 mckelveygreg

The example is throwing a different error than the one you mentioned.

is this the error you mean?

I'm also seeing an error on

image

I'm also seeing an error on the PortableText import though, both are different than your original error.

image

Is the project you're working in a vite project also?

swalker326 avatar Aug 21 '22 14:08 swalker326

Hmmm... that's bizarre. My error appears consistent. image

and yes, we have a vite project, pretty much like the stackblitz example

mckelveygreg avatar Aug 25 '22 22:08 mckelveygreg

I have the same problem with just plain tsc:

$ tsc --noEmit
node_modules/@portabletext/react/src/components/defaults.tsx:1:1 - error TS6133: 'React' is declared but its value is never read.

1 import React from 'react'
  ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@portabletext/react/src/components/list.tsx:1:1 - error TS6133: 'React' is declared but its value is never read.

1 import React from 'react'
  ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@portabletext/react/src/components/marks.tsx:2:1 - error TS6133: 'React' is declared but its value is never read.

2 import React from 'react'
  ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@portabletext/react/src/components/unknown.tsx:1:1 - error TS6133: 'React' is declared but its value is never read.

1 import React from 'react'
  ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@portabletext/react/src/react-portable-text.tsx:1:8 - error TS6133: 'React' is declared but its value is never read.

1 import React, {ReactNode, useContext, useMemo} from 'react'

The problem is probably the d.ts file in dist refers to src directory.

gadkadosh avatar Aug 29 '22 16:08 gadkadosh

@swalker326 Sorry, just realized the React errors on main.tsx and I have no idea why not seems to be exportable from @portabletext/react...

However, it still isn't building and I think @gadkadosh is right that the error is from the d.ts file referring src instead of some dist artifact

mckelveygreg avatar Sep 07 '22 16:09 mckelveygreg

Closing as this appears to be fixed 🤷

mckelveygreg avatar Mar 01 '23 21:03 mckelveygreg