storybook: Storybook build fails with "Cannot find module 'webpack/lib/util/makeSerializable.js" after upgrading storybook packages to 6.3.0
Describe the bug
start-storybook and build-storybook fail with Error: Cannot find module 'webpack/lib/util/makeSerializable.js'
To Reproduce
See this commit: https://github.com/ismay/superwolff/commit/2ef03b79734af55c87d8b58f84422c1e1894a2c2. Chromatic tests here are unchanged, so on CI the build isn’t failing. However a local npm install (even after clearing node_modules) of this commit, and running npm run storybook:start yields the following output:
> storybook:start
> start-storybook -p 6006 --quiet
info @storybook/react v6.3.0
info
info => Loading presets
info => Loading 1 config file in "/Users/ismay/Projects/github/ismay/superwolff/.storybook"
info => Loading 9 other files in "/Users/ismay/Projects/github/ismay/superwolff/.storybook"
info => Adding stories defined in "/Users/ismay/Projects/github/ismay/superwolff/.storybook/main.js"
info => Using prebuilt manager
info => Using implicit CSS loaders
info => Using default Webpack5 setup
<i> [webpack-dev-middleware] wait until bundle finished
node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module 'webpack/lib/util/makeSerializable.js'
Require stack:
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/dependency.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/plugin.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/index.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react/dist/cjs/server/framework-preset-react-docgen.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core-common/dist/cjs/presets.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core-common/dist/cjs/index.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core-server/dist/cjs/index.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core/dist/cjs/server.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core/server.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react/dist/cjs/server/index.js
- /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react/bin/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/dependency.js:6:55)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at /Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/plugin.js:108:42
at _next0 (eval at create (/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/builder-webpack5/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:203:1)
at Hook.eval [as call] (eval at create (/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/builder-webpack5/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:286:1)
at Hook.CALL_DELEGATE [as _call] (/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/builder-webpack5/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
at Compiler.newCompilation (/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1017:26) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/dependency.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/plugin.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react-docgen-typescript-plugin/dist/index.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react/dist/cjs/server/framework-preset-react-docgen.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core-common/dist/cjs/presets.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core-common/dist/cjs/index.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core-server/dist/cjs/index.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core/dist/cjs/server.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/core/server.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react/dist/cjs/server/index.js',
'/Users/ismay/Projects/github/ismay/superwolff/node_modules/@storybook/react/bin/index.js'
]
}
System
Environment Info:
System:
OS: macOS 11.3
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Binaries:
Node: 15.14.0 - /var/folders/61/0bv_jh4j7jv0znfdbw6p5c180000gn/T/fnm_multishells/21506_1624468041471/bin/node
npm: 7.9.0 - /var/folders/61/0bv_jh4j7jv0znfdbw6p5c180000gn/T/fnm_multishells/21506_1624468041471/bin/npm
Browsers:
Chrome: 91.0.4472.114
Firefox: 89.0.1
Safari: 14.1
npmPackages:
@storybook/addon-actions: ^6.3.0 => 6.3.0
@storybook/addon-essentials: ^6.3.0 => 6.3.0
@storybook/addon-links: ^6.3.0 => 6.3.0
@storybook/builder-webpack5: ^6.3.0 => 6.3.0
@storybook/manager-webpack5: ^6.3.0 => 6.3.0
@storybook/react: ^6.3.0 => 6.3.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 89
- Comments: 94 (25 by maintainers)
Commits related to this issue
- Fix bug with webpack5, storybook 6.4.0-alpha, and react-docgen-typescript-plugin - tl;dr : Add a resolutions field. Note that this field needs to be in the root workspace to have any effect, and so... — committed to splitgraph/splitgraph.com by milesrichardson 3 years ago
- Fix bug with webpack5, storybook 6.4.0-alpha, and react-docgen-typescript-plugin - tl;dr : Add a resolutions field. Note that this field needs to be in the root workspace to have any effect, and so... — committed to splitgraph/splitgraph.com by milesrichardson 3 years ago
- Fix bug with webpack5, storybook 6.4.0-alpha, and react-docgen-typescript-plugin - tl;dr : Add a resolutions field. Note that this field needs to be in the root workspace to have any effect, and so... — committed to splitgraph/splitgraph.com by milesrichardson 3 years ago
- fix(storybook): make it work with VanillaExtract refer to https://github.com/seek-oss/vanilla-extract/discussions/371 and https://github.com/storybookjs/storybook/issues/15336#issuecomment-922418262 — committed to AlexKMarshall/invoice-app-next by AlexKMarshall 3 years ago
- fix: upgrade storybook to 6.5 alpha to get docs' storybook working https://github.com/storybookjs/storybook/issues/15336 — committed to chrisolsen/ui-components by chrisolsen 2 years ago
- chore: add ts config for sb, use webpack5 - https://storybook.js.org/docs/react/configure/typescript#mainjs-configuration - https://storybook.js.org/blog/storybook-for-webpack-5/ - https://gist.githu... — committed to sozonome/spoker by sozonome 2 years ago
- chore(storybook): setup storybook (#49) * chore: init storybook * chore(storybook): configure storybook Ref: - https://github.com/storybookjs/storybook/issues/13486#issuecomment-755418523 - h... — committed to sozonome/spoker by sozonome 2 years ago
- fix: upgrade storybook to 6.5 alpha to get docs' storybook working https://github.com/storybookjs/storybook/issues/15336 — committed to chrisolsen/ui-components by chrisolsen 2 years ago
- :bug: get error message and add option to fix why: get this Error: Cannot find module 'webpack/lib/util/makeSerializable.js' and check this url https://github.com/storybookjs/storybook/issues/15336 — committed to knj-labo/tic-tac-toe by mono-tmt 2 years ago
- :bug: get error message and add option to fix why: get this Error: Cannot find module 'webpack/lib/util/makeSerializable.js' and check this url https://github.com/storybookjs/storybook/issues/15336 — committed to knj-labo/tic-tac-toe by jp-knj 2 years ago
- :bug: get error message and add option to fix why: get this Error: Cannot find module 'webpack/lib/util/makeSerializable.js' and check this url https://github.com/storybookjs/storybook/issues/15336 — committed to knj-labo/tic-tac-toe by jp-knj 2 years ago
- fix error with running storybook webpack5に切り替えて実行すると以下のエラーが出る。 ``` Error: Cannot find module 'webpack/lib/util/makeSerializable.js' ``` これは、探してみると以下のissueのワークアラウンドで解決できた。 https://github.com/storybo... — committed to MH4GF/log.mh4gf.dev by MH4GF 2 years ago
- [config]: sb@latest - Cannot find module 'webpack/lib/util/makeSerializable.js' https://github.com/storybookjs/storybook/issues/15336 - typescript: { reactDocgen: false }, It seems that storybook wa... — committed to yjkwon07/DCS-uikit by yjkwon07 2 years ago
- install webpack5 more details: https://dev.to/lico/storybook-webpack-5-error-cannot-find-module-webpacklibutilmakeserializablejs-109m https://github.com/storybookjs/storybook/issues/15336 — committed to sergeylukin/chapp by sergeylukin 2 years ago
- Cannot find module エラーへの対処 .storybook/main.js に typescript: { reactDocgen: false } を追記 https://dev.classmethod.jp/articles/tried-to-add-storybook-to-nextjs-project/ https://github.com/storybookjs/st... — committed to nobu09/nextjs-gihyo-book by nobu09 a year ago
I was only able to fix this by adding this:
typescript: { reactDocgen: false },It seems that storybook was still trying to reference webpack 4 until I switched this toggle off.
THIS WORKED FOR ME! 🎉
in case anyone else wants to try this: add
typescript: { reactDocgen: false },into module.exports inside .storybook/main.jsDid you try installing
webpack5as a project dependency?Do you have a repro you can share? You can create a reproduction by running
npx sb@next repro, following the instructions, and linking it in your issue description. We prioritize issues with reproductions over those without. Thank you! 🙏I ran into this issue while following the NextJS + Storybook guide - https://storybook.js.org/blog/get-started-with-storybook-and-next-js/
I was able to solve it by installing webpack 5 in my dev dependencies.
In case this helps anyone, here’s what my package.json looks like:
Hello, we’re in the same situation. Adding webpack@5 in our dev dependencies doesn’t solve the issue for us, we still have the same error. We’re in a monorepo using yarn workspaces.
EDIT :
It seems to work that way :
yarn add -W -D webpackwebpack: "*"in peerDependencies of your package.typescript: { reactDocgen: false },it worked! 🚀This issue is still present in @storybook/react 6.4.9 and 6.5.0-alpha.1. Using
npx sb init --builder webpack5and Next.js.Adding Webpack5 as dev dependencies fix the issue regardless of any version of storybook
The solution is simply to add the following to .storybook\main.js
reactDocgen: false
Example
@shilman I am facing the same issue. After manually adding webpack 5 I receive this errors in the install:
It seems that internally some storybook features still point to webpack4?
Installing webpack5 with
--legacy-peer-depsworks. Do I still need to add the@storybook/builder-webpack5to theaddonssection of main.js? This is not mentioned in the migration docs.typescript: { reactDocgen: false },is a BAD FIX because then you will loose Storybook Control feature.As some people mentioned before, you need to have
webpack5dependency:npm install --save-dev webpack~Only fix that will work with yarn berry (PnP) is if
@storybook/react-docgen-typescript-plugindeclares webpack 5 as a full dependency vs a peer dependency otherwise the hoisting just won’t work deterministically. I had to manually edit the yarn lock file to get this to work:~EDIT: Here’s the addition to package.json that worked for me:
If you’re using npm >= 8.6.0, add the following to your top-level package.json:
If using npm >= 8.3.0 < 8.6.0, that would also work, but you’d have to delete package-lock.json before it takes effect, this is a known bug.
w00t!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.11 containing PR #16752 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
@raulvictorrosa Try @patrick-mcdougle solution, but make sure to do a clean install after you’ve added
resolutionsfield topackage.json:If you’re on a monorepo with Yarn, try this in your root package.json:
This did not work for me either.
Reiterating what worked for me:
Until webpack 4 is completely out of the storybook packages this still has a chance of being hoisted wrong. OR react-docgen-typescript-plugin needs to bump the peerDependency version to >= 5.
@shilman reopen is not an option for me, so a maintainer will have to reopen this.
This works for me. Here is the complete
module.exportsin.storybook/main.jsIsn’t this line the root of the problem?: https://github.com/storybookjs/storybook/blob/main/addons/docs/src/frameworks/common/preset.ts#L9
I’m not too familiar with storybooks code base, but to me this looks like it is always using webpack4 for docs. Also it says “fixme”… But as long as this is the case I don’t think storybook can be listed as being fully compatible with yarn pnp. Unfortunately it also looks like there’s no workaround other than not using pnp at all.
Edit: Found out you can put webpack 5 into the
resolutionsin package.json. This causes half a million errors in the console, but the end result appears to be working fine regardless 😮It isn’t fully solving the issue actually, now if I install new deps, I have the error again. I need to wipe all my monorepo node_modules folders and install from scratch to make the error disappear, it’s quite annoying.
I just wanted to mention here that installing webpack5 had gotten my Storybook issue back on track. I used this code, we’re running storybook.js with React.
npm i -D webpack@^5.x.xThanks @patrick-mcdougle !!! 🙏 Continuing the conversation on the PR
Edit: The error only started appearing for me after switching to Yarn’s Plug’n’Play and I’ve only been using Webpack 5 in the project (not just for storybook but also for the normal build process and yes it’s listed as a dependency). The workaround of installing webpack 5 will make it hoisted but it won’t work if you’re using Yarn’s pnp. Yarn also complains about
@storybook/corenot declaring its peer dependencies on babel and webpack so that’s probably related.For anyone in a mono repo using
pnpm, I was able to fix it with:find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +pnpm iI have a mono repo, NextJS, and Storybook.
yup, thanks @quantran020173 and @mdirshaddev.
yarn add webpack@5 --devworked like a charm.I can confirm @jgoux workaround for yarn-based monorepos. Only installing
webpack@5at the root workspace did it for me.It looks like a conflict from the version used by
@storybook/react-docgen-typescript-plugin. Here’s the resolution from yarn that spawned the same error for me:I can reproduce this issue with the current latest version of webpack here: https://github.com/Codecademy/client-modules/pull/1404/commits/d45f6dca52db943b653b9ddb639915ee8bd28df3. Sorry the reproduction is so complex; it’s the only one I’ve got 😉 .
The CircleCI builds are private but you can clone the repository locally, build all packages, and
yarn startto reproduce:Adding webpack to the
devDependenciesinpackages/styleguide/package.jsonindeed resolves the crash: https://github.com/Codecademy/client-modules/pull/1404/commits/1d4780d2b6f55144599da1aeddab9aebce18cb85The offending lines of code were a chuckle:
This fix worked for me when adding Storybook to Turborepo. Saved me a major headache on a Friday afternoon, thanks
If you’re running into this, it may be because a package is in your production dependencies that also depends on webpack 4 directly. If you’re on yarn,
yarn whymay help explain why webpack4 is being hoisted still.In our case, it was because storybook was added to production dependencies by accident.
This also works for a monorepo with nx and npm!
I just did it and the issue persist 😦
UPDATE I had to install webpack5 on devDependencies.
Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.14 containing PR #17192 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Disabling reactDocgen means that it will no longer be able to automatically infer your props from your component, so you’d have to manually tell storybook about each prop and their type.
This solved the issue !
I think this issue is still present. I upgraded to
6.4.0and I’m still getting the same error. Here is a reproduction repo; just runyarn sbto see the error.I see, so need to add a switch detecting which builder we’re on… On it!
@thedavidprice that’s wonderful news! 🙌 if you come across any learnings that should be incorporated on the storybook side, please share. and congrats on the big upcoming release!
I had the same issue from 6.29 (using npx sb init --builder webpack5 -f to install few weeks back) to 6.3. Upgrading to latest webpack fixed