storybook: Webpack v5 Upgrade - `start-storybook` works but `build-storybook` fails
Describe the bug
I recently upgrade my project to Webpack v5. The start-storybook command works just fine, but when I run build-storybook, I get the following error:
info @storybook/react v6.1.11
info
info => Cleaning outputDir C:\Dev\bkp-client\storybook-static
info => Building manager..
info => Loading manager config..
info => Loading presets
info => Loading custom babel config
info => Compiling manager..
C:\Dev\bkp-client\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js:119
throw new TypeError(
^
TypeError: The 'compilation' argument must be an instance of Compilation
at Function.getCompilationHooks (C:\Dev\bkp-client\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js:119:10)
at C:\Dev\bkp-client\node_modules\terser-webpack-plugin\dist\index.js:571:67
at SyncHook.eval [as call] (eval at create (C:\Dev\bkp-client\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:87:1)
at SyncHook.lazyCompileHook (C:\Dev\bkp-client\node_modules\tapable\lib\Hook.js:154:20)
at C:\Dev\bkp-client\node_modules\@storybook\core\node_modules\webpack\lib\Compiler.js:667:29
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Dev\bkp-client\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Dev\bkp-client\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.compile (C:\Dev\bkp-client\node_modules\@storybook\core\node_modules\webpack\lib\Compiler.js:662:28)
at C:\Dev\bkp-client\node_modules\@storybook\core\node_modules\webpack\lib\Compiler.js:321:11
at Array.<anonymous> (C:\Dev\bkp-client\node_modules\@storybook\core\node_modules\webpack\lib\Compiler.js:534:20)
at Storage.finished (C:\Dev\bkp-client\node_modules\@storybook\core\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at C:\Dev\bkp-client\node_modules\@storybook\core\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at callback (C:\Dev\bkp-client\node_modules\graceful-fs\polyfills.js:295:20)
at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! code 1
I saw a similar error with the html-webpack-plugin, so it may just be that Storybook 6 is incompatable with Webpack 5, but it’s strange that start-storybook works while build-storybook fails.
To Reproduce Use Storybook with Webpack v5.
Expected behavior
I would expect that a working start-storybook implies that build-storybook works as well. It’s a bit confusing to have my normal Storybook workflow work perfectly but the build tools are unable to build. How does start-storybook actually work if it’s not building the Storybook?
System Environment Info:
System: OS: Windows 10 10.0.18363 CPU: (8) x64 Intel® Core™ i7-8565U CPU @ 1.80GHz Binaries: Node: 14.15.1 - C:\Program Files\nodejs\node.EXE npm: 7.5.3 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 88.0.4324.150 Edge: Spartan (44.18362.449.0) npmPackages: @storybook/addon-actions: ^6.1.11 => 6.1.11 @storybook/addon-links: ^6.1.11 => 6.1.11 @storybook/addons: ^6.1.11 => 6.1.11 @storybook/preset-typescript: ^3.0.0 => 3.0.0 @storybook/react: ^6.1.11 => 6.1.11 @storybook/storybook-deployer: ^2.8.7 => 2.8.7
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 13
- Comments: 39 (9 by maintainers)
@shilman for some reason, my setup broke after updating preview to
webpack@5.32.0https://github.com/JetBrains/ring-ui/tree/dependabot/npm_and_yarn%2Fwebpack-5.32.0
npm install && npm run bootstrap && npm run buildSame issue for me as @Hypnosphi has above using
webpack:5.35.1, I tried to install storybook in a clean project withnpx sb@next init --builder webpack5and I have this result when runningstart-storybook:I ran into a similar problem and had to install both
html-webpack-plugin@latestandterser-webpack-plugin@latestmanually to resolve everything. To figure out which plugin you need to install check the stacktrace that’s included in the error. The second line starting withatusually shows which dependency is causing the issue.So in the previous comment by @daviddelusenet, the first stacktrace includes the following on the second line. Installing
html-webpack-pluginsolved this for @daviddelusenet.The last snippet in that same comment includes the following on the second line.
This indicates that
terser-webpack-pluginis now the one causing the error so that also needs to be installed vianpm install --save-dev terser-webpack-plugin@latestto ensure the correct version is resolved when compiling.Hope this helps anyone ✌🏼
@marjisound’s
npm i terser-webpack-plugin && npm remove terser-webpack-pluginfixed it for us 👏I encountered a similar issue with the terser pluggin ( Storybook v7.0.0-alpha.47 + Angular 13 ), my workarround was to apply the following change in the webpackFinal parameter of
.storybook/main.jsI install terser-webpack-plugin by way of
npm i -D terser-webpack-plugin. It works. But I still don’t understand why I needterser-webpack-plugin.I encounter exactly this when trying to follow https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324
Reproduction: https://github.com/JetBrains/ring-ui/tree/webpack-5
This solved the problem for us too
I think this has to do with the storybook init installing both the webpack 4 and webpack 5 packages. The dependency for terser-webpack-plugin in webpack 4 is trumping the one in webpack 5 so it is breaking when trying to build with webpack 5. Manually installling terser-webpack-plugin then fixes the dependency but I think the ultimate fix should be for Storybook to remove all of the webpack 4 packages for users using webpack 5.
Same for me!
Just to chime in, I have hit precisely the same issue as @Hypnosphi has above using webpack 5.33.2
Hey @lanesawyer! Storybook doesn’t currently support Webpack 5. You can check out the ongoing progress in https://github.com/storybookjs/storybook/pull/13808
I’m going to close this up because the webpack 5 epic is #9216
Still not working for me with your procedure @milosrs . I never had
@storybook/create-react-appplugin (I don’t use create-react-app). I’m withnpm 7.11.1andwebpack 5.24.3andnode 14.15.5This is your answer: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#upgrade
Same issue with webpack 5. Is there any workaround around ?
Thanks @shilman We actually managed to fix the
TypeError: The 'compilation' argument must be an instance of Compilationissue for build-storybook by tweaking the way terser-webpack-plugin is installed =>npm i terser-webpack-plugin && npm remove terser-webpack-pluginBut now we are having a new issue on both build-storybook & start-storybook for ts-loader module build
TypeError: Cannot read property 'tap' of undefinedfor which I created a new issue https://github.com/storybookjs/storybook/issues/14170EDIT: I’ve added a line to bump Storybook to its latest version. (Original sample was still at BETA 5.)
You may want to use the https format of the repo:
Hope it helps!
@shilman I see. I think I’ll just extract custom-header into a separate lerna package with its own dependencies