-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug] "Invalid hook call" error after upgrading to Storybook 6 #11904
Comments
Do you have a minimal repro for this? This project takes 10m to install on my (fast) machine & the build errors on something unrelated to storybook. |
Only happened to me after I installed the new React RC version. Probably the error was having multiple copies of React If anyone interested, worked for me with [email protected] and [email protected] |
I've also seen issues where there are multiple copies of See for example: #11373 (comment) |
@shilman makes sense because I have a custom addon depending in 5.2.8 version, I'll update and see what happens |
It's caused by multiple versions of React being loaded - Fixes:
|
@thebuilder it's caused by some class of errors in the rendering, not necessarily only multiple versions of React. The issue i mentioned above had a single version of React but multiple versions of |
Pretty sure the specific error in this issue, is caused by mismatching React versions. I got the same stacktrace trying to run Storybook after upgrading to 6.0, and aligning React solved it.
It fails to share the emotion theme context between different React versions. The issue (#11373) you're linking too has a different Stacktrace - properly also caused by mismatching dependencies. |
Fair enough. I wanted to clarify for anyone who comes to this issue so that they don't overfit, especially when it explicitly warns about multiple versions of React in the error. |
We are running into this issue as well. All the When I ran => Found "[email protected]"
info Has been hoisted to "react"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "244KB"
info Disk size with unique dependencies: "496KB"
info Disk size with transitive dependencies: "576KB"
info Number of shared dependencies: 5
=> Found "@storybook/addon-actions#[email protected]"
info This module exists because "@storybook#addon-actions" depends on it.
info Disk size without dependencies: "276KB"
info Disk size with unique dependencies: "528KB"
info Disk size with transitive dependencies: "608KB"
info Number of shared dependencies: 5
=> Found "@storybook/api#[email protected]"
info This module exists because "@storybook#addon-actions#@storybook#api" depends on it.
info Disk size without dependencies: "276KB"
info Disk size with unique dependencies: "528KB"
info Disk size with transitive dependencies: "608KB"
info Number of shared dependencies: 5
=> Found "@storybook/components#[email protected]"
info This module exists because "@storybook#addon-actions#@storybook#components" depends on it.
info Disk size without dependencies: "276KB"
info Disk size with unique dependencies: "528KB"
info Disk size with transitive dependencies: "608KB"
info Number of shared dependencies: 5
=> Found "@storybook/ui#[email protected]"
info This module exists because "@storybook#react#@storybook#core#@storybook#ui" depends on it.
info Disk size without dependencies: "276KB"
info Disk size with unique dependencies: "528KB"
info Disk size with transitive dependencies: "608KB"
info Number of shared dependencies: 5 I then saw that Storybook brought in -react-dom@^16.13.1:
+react-dom@^16.13.1, react-dom@^16.8.3:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
@ -12361,16 +12361,6 @@ react-dom@^16.13.1:
prop-types "^15.6.2"
scheduler "^0.19.1"
-react-dom@^16.8.3:
- version "16.10.2"
- resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.2.tgz#4840bce5409176bc3a1f2bd8cb10b92db452fda6"
- integrity sha512-kWGDcH3ItJK4+6Pl9DZB16BXYAZyrYQItU4OMy0jAkv5aNqc+mAKb4TpFtAteI6TJZu+9ZlNhaeNQSVQDHJzkw==
- dependencies:
- loose-envify "^1.1.0"
- object-assign "^4.1.1"
- prop-types "^15.6.2"
- scheduler "^0.16.2"
-react@^16.13.1:
+react@^16.13.1, react@^16.8.3:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
@ -12656,15 +12646,6 @@ react@^16.13.1:
object-assign "^4.1.1"
prop-types "^15.6.2"
-react@^16.8.3:
- version "16.10.2"
- resolved "https://registry.yarnpkg.com/react/-/react-16.10.2.tgz#a5ede5cdd5c536f745173c8da47bda64797a4cf0"
- integrity sha512-MFVIq0DpIhrHFyqLU0S3+4dIcBhhOvBE8bJ/5kHPVOVaGdo0KuiQzpcjCPsf585WvhypqtrMILyoE2th6dT+Lw==
- dependencies:
- loose-envify "^1.1.0"
- object-assign "^4.1.1"
- prop-types "^15.6.2" When running => Found "[email protected]"
info Has been hoisted to "react"
info Reasons this module exists
- Specified in "devDependencies"
- Hoisted from "@storybook#addon-actions#react"
- Hoisted from "@storybook#addon-actions#@storybook#api#react"
- Hoisted from "@storybook#addon-actions#@storybook#components#react"
- Hoisted from "@storybook#react#@storybook#core#@storybook#ui#react"
info Disk size without dependencies: "244KB"
info Disk size with unique dependencies: "496KB"
info Disk size with transitive dependencies: "576KB"
info Number of shared dependencies: 5 Another solution is to add the React Version you need in the
Thank you @thebuilder for pointing me in the right direction! |
@wtanna did you use |
@shilman I used ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/semver@^7.3.2
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/semver@^7.3.2
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/semver@^7.3.2
├─ @storybook/[email protected]
├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/[email protected]
│ ├─ @storybook/semver@^7.3.2
│ ├─ @storybook/[email protected] |
@shilman unfortunately, I haven't been able to create a minimal repository yet. I will try some fixes and, if nothing works, I try to create this minimal repository. Thank you very much :) |
@gabrielseco I'm trying with version 6.0.5, I didn't get to use RC versions. |
@wtanna OK sorry for the false alarm. Just wanted to be sure because if some of the packages were out of date it could also lead to other problems aside from the one that this issue focuses on. |
I had this problem, then literally just upgraded from 6.0.5 to 6.0.6 via "npx sb upgrade" and voila, all is working! |
@JeremyGrieshop I tried to upgrade to |
Still not working using sb 6.0.7 and react 17.0.0-rc.0 |
I was able to solve this problem by removing the main.js file and restoring my config.ts file:
Although I get this deprecation warning:
At least I don't get the "Invalid hook call" errors and storybook works (for now). |
I can confirm that deleting my |
Not sure if this is the same issue, but I'm also getting the This was with react 17.0.0-rc.0, and downgrading to 16.13.1 resolved the issue. |
Can confirm that this solved the problem for us. Storybook 6 here we come! :D |
I was following the Install Storybook and got this error. Run the followings solved the problem.
|
This helped me as well. Thanks for posting your solution. |
We use npm and ran into the same issue. I fixed it by uninstalling all the storybook packages (which cleaned up package-lock) and then reinstalling with Note that this will overwrite your storybook config so make sure to check the diff and restore your customizations. |
@jizusun's solution worked for me, but I believe until this issue is fixed, this should be at least mentioned in the get started tutorial here: This seems to be a great library, but the start sure is rough! Not being able to just start following the tutorial and waisting a lot of time looking for how to fix this issue is just plain sad. |
@shilman thanks to the team for putting in that effort into the prerelease. I just upgraded to it and my I should attempt some tests with v17 at a later stage. |
You don't have to delete your entire lock file. Simply remove all dependencies that rely on React. See which ones by running Running Install the dependencies again and yarn will resolve to the same React version (if they are compatible). Bonus, add this script to CI to make sure you don't end up in this situation again: #!/bin/bash
HOW_TO_FIX="If you got this error after updating React, you might have to temporarily remove the other dependencies that rely on React, such as Storybook. This will remove the extra React versions from the lock file. Then add the latest version of these dependencies and yarn should resolve to the same version of React."
VERSIONS_OF_REACT=$(yarn why react | grep -cF "=> Found") && [[ $VERSIONS_OF_REACT == 1 ]] || (echo "Found $VERSIONS_OF_REACT versions of React in dependencies, there should only be 1. $HOW_TO_FIX" && false) |
Upgrading |
|
Followed these instructions, with no effect. Still getting the same error. |
Hey everyone. I was suffering the same error, but on a fresh new "create-react-app". Workaround by: (re)Installing storybook specifying type |
Hi, I had the same issue, it's a bit unexpected when you are excited discovering a quite new world (react + storybook) and after 5 minutes you are stuck in dependencies "deadlock". The new version React 17 seems not to be compatible with Storybook 6.0 (latest stable version). I followed the recommendations and I upgraded to SB 6.1.0 alpha version and it works (how confident may I be to proceed with this weak dependency ?)! Thanks for your support. |
Same issue. Can't load any story. I only used the following two commands:
|
Duplicate to #12408 |
I'm getting this problem as well, unless I remove the export default {
title: 'AwesomeComponent',
// component: AwesomeComponent,
}; I don't know if it's one component causing this issue, or all of them, or some of them, but I don't want to find out, because it's not the components that are written incorrectly. Our linting rules should catch if hooks are incorrectly used, and linting the entire project products no errors and no warnings. @shilman Can you please provide a workaround or fix in Storybook 6.0 where we can still have the |
@thany No. The fix for this is destabilizing, so we are releasing it as quickly as possible in 6.1. |
My library is importing a component from a package that has: "peerDependencies": {
"react": "^17.0.2"
}, I tried everything described in this issue. Nothing seems to solve the problem. Any idea? |
Are you sure it's actually related? A peer dependency is the correct way to depend on React, so it's most probably not your issue. If you stop importing this package, it does work again? How is "react-dom" installed? |
Yes sorry for the noise, it wasn't related at all 😄. Thank you for your answer @eric-burel |
@shilman After upgraded to SB v7, I am stucked with a similar issue for couple days, can you help unblocking me. I am writing a react lib with "react" and "react-dom" as peer dependency, then I have a seperate storybook project demoing the usage of the lib. The package.json of the lib: {
"name": "sdk",
...,
"scripts": {
"dev": "NODE_ENV=development rollup -c -w --bundleConfigAsCjs",
"build": "NODE_ENV=production rollup -c --bundleConfigAsCjs",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint '*.{js,json}' 'src/**/*.{ts,tsx}'",
"lint:fix": "eslint --fix '*.{js,json}' 'src/**/*.{ts,tsx}'",
"prettier": "prettier -w src .github",
"prettier:check": "prettier --check src .github",
"dry-run-release": "semantic-release --dry-run"
},
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.esm.js",
"types": "./dist/index.d.ts"
},
"./components": {
"require": "./dist/index.js",
"import": "./dist/index.esm.js",
"types": "./dist/components/index.d.ts"
},
"./stores": {
"require": "./dist/index.js",
"import": "./dist/index.esm.js",
"types": "./dist/stores/index.d.ts"
},
"./hooks": {
"require": "./dist/index.js",
"import": "./dist/index.esm.js",
"types": "./dist/hooks/index.d.ts"
}
},
"typesVersions": {
"*": {
"components": [
"dist/components"
],
"stores": [
"dist/stores"
],
"hooks": [
"dist/hooks"
]
}
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@headlessui/react": "^1.7.4",
"@heroicons/react": "^1.0.5",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.2.1",
"@rollup/plugin-typescript": "^10.0.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@tailwindcss/container-queries": "^0.1.0",
"@testing-library/react": "^13.4.0",
"@types/jest": "^27.4.0",
"@types/node": "^20.1.7",
"@types/react": "^18.0.26",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"autoprefixer": "^10.4.1",
"babel-jest": "^27.4.5",
"babel-loader": "^8.2.3",
"eslint": "^8.20.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.1",
"identity-obj-proxy": "^3.0.0",
"immer": "^9.0.12",
"jest": "^27.4.5",
"lint-staged": "^13.0.3",
"postcss": "^8.4.23",
"postcss-cli": "^9.1.0",
"prettier": "^2.7.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^3.9.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"semantic-release": "^19.0.3",
"tailwindcss": "^3.2.4",
"ts-deepmerge": "^2.0.1",
"tslib": "^2.3.1",
"typescript": "^4.9.5",
"webpack": "5.65.0"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"dependencies": {
"@tanstack/react-query": "^4.24.6",
"ace-builds": "^1.21.1",
"echarts": "^5.3.2",
"echarts-gl": "^2.0.9",
"fabric": "link:../../Libs/fabric.js",
"jotai": "^2.1.0",
"rc-slider": "^10.1.0",
"rc-tooltip": "^5.2.2",
"rc-util": "^5.30.0",
"react-ace": "^10.1.0",
"react-resize-detector": "^9.1.0",
"react-toastify": "^8.1.1",
"zustand": "^4.1.1"
}
} The import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
const packageJson = require('./package.json');
const isProduction = process.env.NODE_ENV === 'production';
const deps = Object.keys(packageJson.dependencies || {});
export default [
{
input: 'src/index.ts',
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: !isProduction,
},
{
file: packageJson.module,
format: 'esm',
sourcemap: !isProduction,
},
],
watch: {
clearScreen: false,
include: 'src/**',
exclude: [
'node_modules/**',
'dist/**',
'examples/**',
'src/**/*.stories.tsx',
],
},
plugins: [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
compilerOptions: {
sourceMap: !isProduction,
inlineSources: !isProduction,
...(!isProduction && { target: 'esnext' }),
},
}),
isProduction &&
terser({
format: {
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/,
},
}),
postcss({
config: {
path: './postcss.config.js',
},
extensions: ['.css'],
minimize: isProduction,
extract: false,
inject: true,
}),
],
external: (id) => {
const [pkg] = id.split('/');
return deps.includes(pkg);
},
},
]; And following is the {
"name": "sdk-storybook",
...,
"main": "index.js",
"scripts": {
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"devDependencies": {
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@storybook/addon-essentials": "^7.0.12",
"@storybook/addon-interactions": "^7.0.12",
"@storybook/addon-links": "^7.0.12",
"@storybook/addon-styling": "^1.0.8",
"@storybook/blocks": "^7.0.12",
"@storybook/react": "^7.0.12",
"@storybook/react-webpack5": "^7.0.12",
"@storybook/testing-library": "^0.0.14-next.2",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.23",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.12",
"tailwindcss": "^3.3.2"
},
"dependencies": {
"sdk": "link:../sdk",
"echarts": "^5.4.2",
"zustand": "^4.3.8"
}
} This settings works well when I am using
|
@ZhengRui can you please open a new issue with a minimal reproduction and we'd be happy to take a look |
hey @shilman , i setup a minimal reproduction, and i opened this discussion , thank you for taking a look ! |
Describe the bug
I am updating Storybook to version 6 in my project. After making some minor adjustments, such as installing two missing @types libraries, I believed that I wouldn't need to do anything else, as the Storybook would work.
Steps to reproduce the behavior
renovate/major-storybook-monorepo
;yarn install
to install all dependencies;packages/web
and, if needed, runyarn install
again;yarn run storybook:start
;I also tried to delete all files inside of
.storybook
and keep an emptymain.js
, and it still does not work.Expected behavior
The Storybook application should load, even if warnings or errors appear on the console.
Screenshots
System
Additional context
Trace
The text was updated successfully, but these errors were encountered: