Skip to content
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

Storybook build fails with "Cannot find module 'webpack/lib/util/makeSerializable.js" after upgrading storybook packages to 6.3.0 #15336

Closed
ismay opened this issue Jun 23, 2021 · 94 comments

Comments

@ismay
Copy link

ismay commented Jun 23, 2021

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 
@shilman
Copy link
Member

shilman commented Jun 23, 2021

Did you try installing webpack5 as 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! 🙏

@dohomi
Copy link

dohomi commented Jun 24, 2021

@shilman
I am facing the same issue. After manually adding webpack 5 I receive this errors in the install:

Could not resolve dependency:
npm ERR! peer webpack@"^2.0.0 || ^3.0.0 || ^4.0.0" from webpack-filter-warnings-plugin@1.2.1
npm ERR! node_modules/webpack-filter-warnings-plugin
npm ERR!   webpack-filter-warnings-plugin@"^1.2.1" from @storybook/builder-webpack4@6.3.0
npm ERR!   node_modules/@storybook/builder-webpack4
npm ERR!     @storybook/builder-webpack4@"6.3.0" from @storybook/addon-docs@6.3.0
npm ERR!     node_modules/@storybook/addon-essentials/node_modules/@storybook/addon-docs
npm ERR!       @storybook/addon-docs@"6.3.0" from @storybook/addon-essentials@6.3.0
npm ERR!       node_modules/@storybook/addon-essentials
npm ERR!     2 more (@storybook/core-server, @storybook/core-server)

It seems that internally some storybook features still point to webpack4?

Installing webpack5 with --legacy-peer-deps works. Do I still need to add the @storybook/builder-webpack5 to the addons section of main.js? This is not mentioned in the migration docs.

@ismay
Copy link
Author

ismay commented Jun 24, 2021

Did you try installing webpack5 as a project dependency?

Haven't tried that yet.

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! 🙏

Sorry about that, I was a bit pressed for time when I opened this. I'll take a closer look asap and see if I can create a minimal reproduction. Should be this week. I'll try adding webpack 5 as a project dependency as well at that time and report back (weird that apparently the chromatic build doesn't need webpack 5 to be set as a dependency in my project).

@maxmezzomo
Copy link
Contributor

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

@ismay
Copy link
Author

ismay commented Jun 25, 2021

Ok, I've tried to reproduce it, and in messing around with it I seem to have fixed it 'accidentally'. I've narrowed it down to changes in the package-lock.json, those are the only (indirect) changes I made in the end that had an effect on the above bug. For some reason, after multiple rounds of adding/deleting over 20k lines to the package-lock, npm seems to have settled on a combination that works.

I've had this before with updates to storybook, where I have to kind of install and reinstall until the package-lock settles on a combination that works 🤷‍♂️. I can imagine you can't do anything with this as maintainers, so apologies if it's too vague. Feel free to close this issue if it's not actionable.

@JoshuaKGoldberg
Copy link
Contributor

I can reproduce this issue with the current latest version of webpack here: Codecademy/client-modules@d45f6dc. 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 start to reproduce:

git clone https://github.com/Codecademy/client-modules
git checkout d45f6dca52db943b653b9ddb639915ee8bd28df3
cd client-modules
yarn
yarn lerna bootstrap
yarn build-all
yarn start

Adding webpack to the devDependencies in packages/styleguide/package.json indeed resolves the crash: Codecademy/client-modules@1d4780d

The offending lines of code were a chuckle:

// eslint-disable-next-line
// @ts-ignore: What's the right way to refer to this one?
const makeSerializable_js_1 = tslib_1.__importDefault(require("webpack/lib/util/makeSerializable.js"));
// eslint-disable-next-line
// @ts-ignore: What's the right way to refer to this one?
const NullDependency_js_1 = tslib_1.__importDefault(require("webpack/lib/dependencies/NullDependency.js"));

@jgoux
Copy link

jgoux commented Jun 28, 2021

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 :

  • Install webpack@5 at the root of the monorepo yarn add -W -D webpack
  • Add webpack: "*" in peerDependencies of your package.

@tassoevan
Copy link

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:

 @storybook/react@npm:6.3.1
└─ @storybook/react-docgen-typescript-plugin@npm:1.0.2-canary.3c70e01.0 (via npm:1.0.2-canary.3c70e01.0)

@tassoevan
Copy link

I can confirm @jgoux workaround for yarn-based monorepos. Only installing webpack@5 at the root workspace did it for me.

@shobhitsharma
Copy link

@tassoevan Did adding webpack in nohoist in root package.json helps for you for monorepo context?

@josh-stevens
Copy link

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.

@shilman
Copy link
Member

shilman commented Jul 29, 2021

@josh-stevens which version were you using?

@josh-stevens
Copy link

josh-stevens commented Jul 29, 2021

@shilman This is in 6.3.6

Turning off docgen seems to be interfering with some other handy addons so this isn't a great workaround.

@shilman
Copy link
Member

shilman commented Jul 30, 2021

@josh-stevens did you try adding webpack5 as a dev dependency in your project root?

@jgoux
Copy link

jgoux commented Aug 4, 2021

I can confirm @jgoux workaround for yarn-based monorepos. Only installing webpack@5 at the root workspace did it for me.

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.

@mdirshaddev
Copy link

Adding Webpack5 as dev dependencies fix the issue regardless of any version of storybook

@mdirshaddev
Copy link

this thread is really helpful @shilman Thank you.

milesrichardson added a commit to splitgraph/splitgraph.com that referenced this issue Aug 20, 2021
…ript-plugin

- tl;dr : Add a resolutions field. Note that this field needs to
  be in the root workspace to have any effect, and so therefore
  must be repeated in the root package.json of both this repo and
  its parent monorepo.
- Add a longer explanation of what happened in the .ci/chromatic.sh
  script, since package.json doesn't allow comments, and since
  the next time this breaks, it's gonna be in that file
- Bump webpack to absolute cutting edge bleeding nightly super early bird
- In storybook config, explicitly configure react-docgen-typescript-plugin,
  although I have no reason to think it made a difference
- Allow specifying tsconfig file via env var TSCONFIG_FILE, default to tsconfig.json

CU-qthhx6

ref storybookjs/storybook#15336
ref https://github.com/hipstersmoothie/react-docgen-typescript-plugin/blob/31ce4e84008a45269b8524157ad51bf9d191acac/package.json#L81
ref https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324
milesrichardson added a commit to splitgraph/splitgraph.com that referenced this issue Aug 23, 2021
…ript-plugin

- tl;dr : Add a resolutions field. Note that this field needs to
  be in the root workspace to have any effect, and so therefore
  must be repeated in the root package.json of both this repo and
  its parent monorepo.
- Add a longer explanation of what happened in the .ci/chromatic.sh
  script, since package.json doesn't allow comments, and since
  the next time this breaks, it's gonna be in that file
- Bump webpack to absolute cutting edge bleeding nightly super early bird
- In storybook config, explicitly configure react-docgen-typescript-plugin,
  although I have no reason to think it made a difference
- Allow specifying tsconfig file via env var TSCONFIG_FILE, default to tsconfig.json

CU-qthhx6

ref storybookjs/storybook#15336
ref https://github.com/hipstersmoothie/react-docgen-typescript-plugin/blob/31ce4e84008a45269b8524157ad51bf9d191acac/package.json#L81
ref https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324
milesrichardson added a commit to splitgraph/splitgraph.com that referenced this issue Aug 23, 2021
…ript-plugin

- tl;dr : Add a resolutions field. Note that this field needs to
  be in the root workspace to have any effect, and so therefore
  must be repeated in the root package.json of both this repo and
  its parent monorepo.
- Add a longer explanation of what happened in the .ci/chromatic.sh
  script, since package.json doesn't allow comments, and since
  the next time this breaks, it's gonna be in that file
- Bump webpack to absolute cutting edge bleeding nightly super early bird
- In storybook config, explicitly configure react-docgen-typescript-plugin,
  although I have no reason to think it made a difference
- Allow specifying tsconfig file via env var TSCONFIG_FILE, default to tsconfig.json

CU-qthhx6

ref storybookjs/storybook#15336
ref https://github.com/hipstersmoothie/react-docgen-typescript-plugin/blob/31ce4e84008a45269b8524157ad51bf9d191acac/package.json#L81
ref https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324
@lauralouiset
Copy link

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.js

@GuiWain
Copy link

GuiWain commented Sep 2, 2021

typescript: { reactDocgen: false }, it worked! 🚀

@luxalpa
Copy link

luxalpa commented Sep 14, 2021

Can confirm the workaround. It works because for some reason this docgen thing is still using Webpack 4. Should probably get updated.

MH4GF added a commit to MH4GF/log.mh4gf.dev that referenced this issue May 4, 2022
webpack5に切り替えて実行すると以下のエラーが出る。

```
Error: Cannot find module 'webpack/lib/util/makeSerializable.js'
```

これは、探してみると以下のissueのワークアラウンドで解決できた。
storybookjs/storybook#15336 (comment)
webpack5のサポートはまだexperimentalなので仕方なさそうか…
@Grsmto
Copy link

Grsmto commented May 5, 2022

If you're on a monorepo with Yarn, try this in your root package.json:

"resolutions": {
  "webpack": "^5"
}

@konhi
Copy link

konhi commented May 14, 2022

If you're on a monorepo with Yarn, try this in your root package.json:

"resolutions": {
  "webpack": "^5"
}

This also works for a monorepo with nx and npm!

@mohammadid52
Copy link

typescript: { reactDocgen: false }

This Worked. Saved alot of time. thanks

@marcusglowe
Copy link

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 why may help explain why webpack4 is being hoisted still.

In our case, it was because storybook was added to production dependencies by accident.

@16012jan
Copy link

BREAKING CHANGE:webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
future: {
webpack5: true,
},
webpack: (config) => {
config.resolve.fallback = {
util: require.resolve("util/")
};
return config;
},
};

module.exports = nextConfig;

@jsamr
Copy link

jsamr commented Jun 25, 2022

If you're using npm >= 8.6.0, add the following to your top-level package.json:

  "overrides": {
    "webpack": "^5"
  }

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.

yjkwon07 added a commit to yjkwon07/DCS-uikit that referenced this issue Jul 19, 2022
- Cannot find module 'webpack/lib/util/makeSerializable.js' storybookjs/storybook#15336
  - typescript: { reactDocgen: false },
It seems that storybook was still trying to reference webpack 4 until I switched this toggle off.
@ugnelis
Copy link

ugnelis commented Jul 21, 2022

typescript: { reactDocgen: false }, is a BAD FIX because then you will loose Storybook Control feature.

As some people mentioned before, you need to have webpack5 dependency:
npm install --save-dev webpack

@TomJPrice
Copy link

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 :

  • Install webpack@5 at the root of the monorepo yarn add -W -D webpack
  • Add webpack: "*" in peerDependencies of your package.

This fix worked for me when adding Storybook to Turborepo. Saved me a major headache on a Friday afternoon, thanks

@thedaviddias
Copy link

@TomJPrice I'm facing the same issue, I installed pnpm add -D -w webpack at the root of the monorepo and added webpack: "*" as a peerDependencies in my packages/ui folder. I'm still getting the error:

Error: Cannot find module '/Users/user/dev/name-project/packages/ui/node_modules/config/webpack.config'

Anything you did more?

@sean256
Copy link

sean256 commented Aug 14, 2022

For anyone in a mono repo using pnpm, I was able to fix it with:

  1. Delete all node_modules from root, find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
  2. Reinstall all packages from root, pnpm i

I have a mono repo, NextJS, and Storybook.

@IvanDerlich
Copy link

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.

Add that line onto with file?

@TomJPrice
Copy link

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.

Add that line onto with file?

It goes into .storybook/main.js but as mentioned by @ugnelis, you will lose some Storybook functionality. Adding webpack as a peer dependency as somebody mentioned above fixed this error for me.

@coder-sasena
Copy link

The solution is simply to add the following to .storybook\main.js

reactDocgen: false

Example

module.exports = {
  "stories": [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions"
  ],
  "framework": "@storybook/react",
  "core": {
    "builder": "@storybook/builder-webpack5"
  },
  typescript: {
    reactDocgen: false
  },
}

@kismet-lee
Copy link

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.x

@ArtemFedorchuk
Copy link

ArtemFedorchuk commented Jan 20, 2023

@shilman I am facing the same issue. After manually adding webpack 5 I receive this errors in the install:

Could not resolve dependency:
npm ERR! peer webpack@"^2.0.0 || ^3.0.0 || ^4.0.0" from webpack-filter-warnings-plugin@1.2.1
npm ERR! node_modules/webpack-filter-warnings-plugin
npm ERR!   webpack-filter-warnings-plugin@"^1.2.1" from @storybook/builder-webpack4@6.3.0
npm ERR!   node_modules/@storybook/builder-webpack4
npm ERR!     @storybook/builder-webpack4@"6.3.0" from @storybook/addon-docs@6.3.0
npm ERR!     node_modules/@storybook/addon-essentials/node_modules/@storybook/addon-docs
npm ERR!       @storybook/addon-docs@"6.3.0" from @storybook/addon-essentials@6.3.0
npm ERR!       node_modules/@storybook/addon-essentials
npm ERR!     2 more (@storybook/core-server, @storybook/core-server)

It seems that internally some storybook features still point to webpack4?

Installing webpack5 with --legacy-peer-deps works. Do I still need to add the @storybook/builder-webpack5 to the addons section of main.js? This is not mentioned in the migration docs.

You are the best!
After adding to the storybook main.js file this:

core: { builder: 'webpack5', },

Everything compiles well! 🥇 👍🏻

@mahdikhashan
Copy link

For me, switching from yarn to pnpm and adding webpack5 solved the issue for next.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests