storybook: Storybook v6 + vue + tsx -> tsc errors: conflict types with @types/react
Describe the bug
After migration from 5.2 to 6 npx tsc throw errors:
Property 'class' does not exist on type 'DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>'Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<...>, Record<...>>'.
To Reproduce Steps to reproduce the behavior:
- Clone ‘https://github.com/voskresla/sb-migrate-reproduce’
- Run ‘npm i && npx tsc’
Expected behavior No errors )
Screenshots
Code snippets
System: Environment Info:
System: OS: macOS 10.15.4 CPU: (8) x64 Intel® Core™ i7-8557U CPU @ 1.70GHz Binaries: Node: 14.8.0 - ~/.nvm/versions/node/v14.8.0/bin/node npm: 6.14.7 - ~/.nvm/versions/node/v14.8.0/bin/npm Browsers: Chrome: 85.0.4183.102 Firefox: 80.0.1 Safari: 13.1 npmPackages: @storybook/addon-knobs: ^6.0.21 => 6.0.21 @storybook/source-loader: ^6.0.21 => 6.0.21 @storybook/vue: ^6.0.21 => 6.0.21
Additional context
Package @types/react came as deps for @types/react-color and @types/react-syntax-highlighter
If delete types rm -rf ./node_modules/@types/react, everything works like a charm.
Or i can use path in tsconfig to solve this.
compilerOptions.path = {
"react": ["./nothins.d.ts"],
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 26
- Comments: 39 (17 by maintainers)
Commits related to this issue
- build: fix the build script Refs: //github.com/storybookjs/storybook/pull/16629,//github.com/storybookjs/storybook/pull/16630,//github.com/vuejs/vue-next/issues/1033,//github.com/storybookjs/storyboo... — committed to XavierChevalier/jam by deleted user 3 years ago
- Install & Setup Storybook # @types/react との競合について https://github.com/storybookjs/storybook/issues/12505 や https://github.com/johnsoncodehk/volar/discussions/592 に言及されている通り @types/react と競合し型エラーが発生する。... — committed to twin-te/twinte-front by HosokawaR 2 years ago
Is this the same problem?
Seems
@vue/runtime-domhas conflicts with@types/reacterror outputs:
My versions:
Still an issue here. with Vue3 + storybook + PNPM.
Erros like:
You might want to check out https://github.com/johnsoncodehk/volar/discussions/592 for additional workarounds.
Same in my case, only rm -rf ./node_modules/@types/react seems to help…
Same issue here. Builds are breaking because of this.
It was also very hard to find this issue on google. Took me a couple hours to find this thread…
So this issue should be fixed by Vue frameworks/boilerplates authors, to make sure they include those types.
I suppose this is ok 🤔
typesis for global augumented types,for example when you import from
react, it will automatically infer types from@types/react🤔
Would be awesome to land & resolve this -> it’s really a big drawback to not be able to use typescript checking for storybook stories.
Thanks @iamandrewluca for opening the PR (:
I have a monorepo with a couple libraries and a couple apps (all vue and typescript) .
I originally had tons of errors in the format:
After trying a bunch of things I got my storybook ui library successfully running both its storybook via
start-storybook -p 6006and successfully building viavue-tsc --noEmit && vite buildwith the following configs:package.json
.storybook/main.js
tsconfig.json
However, when I go to build it as part of my larger monorepo scripts it still throws type errors on missing React:
I do worry resolving this will just bring back the vue dom and react types conflicting type errors 😕
Still investigatingI first updated this comment once I got the originalIntrinsicElementserrors to go away. I don’t know what specifically caused/fixed those initial type errors (probably a set of bad package versions) but I figured I could share the config that is working (unfolds above).Identified the cause of this last React types error: one of my package typescript libraries had a different tsconfig, so that was picking up React through monorepo (still a bad dumb bug); adding
types: []to the tsconfig.json in that package folder resolved the error.Seeing the same in
5.3.19. Those should probably be listed as dev dependencies?There are a lot of people subscribed on this issue, and I don’t want to continue a back and forth about npm behavior here (happy to dig in more on discord.gg/storybook, though!). Maybe you have an older npm or something, as of recent versions, it should be respecting
optional: true. See https://github.com/npm/rfcs/issues/221#issuecomment-695127530 and https://github.com/npm/cli/issues/2615#issuecomment-784509497.Edit: The more I read the less of this I am certain. It certainly seems like a bug if npm is automatically installing optional peer dependencies, and hopefully other package managers like yarn and pnpm don’t also do this. So regardless, I think it’s still the best approach for the mdx package to take.
I want to give up )) I cannot reproduce the issue in my repo anymore 🤣 Also, it seems that
typesalso won’t help. If TypeScript will find@types/reactin the import tree it will still show the error.So this can be a floating bug, depending on what order TS will start analysing the files 🤔
I just created a file that is not imported anywhere, and inside, I’m importing react. The error appears.
At least we now have more insight about this issue
Tested right now locally, still installs them
Personally I think mdx should use an optional peer dependency. That is the most “correct” way to handle the situation, but they seem to be resisting that approach. Anyone using typescript and react will have react types installed, and those using mdx without typescript should not have the types forced into their node_modules. But again, it’s unfortunately out of our hands here in Storybook.
Correct me if I’m wrong, but the issue seems to be that one of our dependencies,
@mdx-js/reactincludes@types/reactin theirdependencies(https://github.com/mdx-js/mdx/blob/f4d78be5c015e8fab48589efae9507d0304e5e94/packages/react/package.json#L45), and volar (and maybe other vue projects?) will pick up that types file if it is in your node_modules. So, it seems like the only thing that can be done is to submit a PR to@mdx-js/reactto move those types to a devDependency. Would someone here like to do that? I think it would be best coming from someone who is directly impacted, maybe @iamandrewluca since you seem pretty knowledgable about what’s happening here?@l10rdev yes this definitely gonna work for you
just make sure to remove node_module, run again
yarnand restart your VS Code.As far as I know this is still an issue and causing trouble in my Preact codebase. Working around it by deleting the node module myself is tedious and a bit hacky. Is there a way for Storybook to address this so non-react projects don’t pull in react types?
I’m also experiencing this issue on a Preact-based project. The error shows up in VSCode, but compilation actually works fine:
It’s mostly an annoyance, but would be great if we can get it sorted since it introduces more confusion when developing.
Packages being used: