storybook: Javascript heap out of memory when doing build-storybook
Describe the bug When trying to do build-storybook it gets to 92% and then fails with the following out of memory error:
92% chunk asset optimization TerserPlugin
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF7CF93EEE5
2: 00007FF7CF918CD6
3: 00007FF7CF9196E0
4: 00007FF7CFD80D3E
5: 00007FF7CFD80C6F
6: 00007FF7CFCCC594
7: 00007FF7CFCC2B67
8: 00007FF7CFCC10DC
9: 00007FF7CFCCA0B7
10: 00007FF7CFCCA136
11: 00007FF7CFDEF7B7
12: 00007FF7CFEC87FA
13: 000000D1798DC6C1
error Command failed with exit code 134.
The entirety of my source code is less than 1 MB so not sure why I would be OOM.
To Reproduce Steps to reproduce the behavior:
Run yarn build-storybook
Expected behavior The build shouldn’t fail.
Screenshots If applicable, add screenshots to help explain your problem.
Code snippets
My current webpack.config.js
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
// This line added as an earlier solution to this OOM error
minimizer: [new TerserPlugin({ parallel: false })],
},
resolve: {
extensions: ['.ts', '.tsx']
},
module: {
rules: [{
test: /\.js$/,
use: 'source-map-loader',
exclude: /node_modules/,
enforce: 'pre'
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader", options: {
sourceMap: true
}
}, {
loader: "sass-loader", options: {
sourceMap: true
}
}]
},
{
test: /\.stories\.tsx?$/,
loaders: [{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: {
parser: 'typescript'
}
}],
enforce: 'pre',
}
]
}
}
My current .storybook config.js
import { addDecorator, configure } from '@storybook/react';
import { withOptions } from '@storybook/addon-options';
import { withKnobs } from '@storybook/addon-knobs';
// add withKnobs
addDecorator(withKnobs);
// Option defaults:
// Full settings here: https://github.com/storybooks/storybook/tree/master/addons/options
addDecorator(
withOptions({
name: 'some-package Storybook',
showAddonPanel: false,
addonPanelInRight: true,
showStoriesPanel: false,
sortStoriesByKind: true
})
);
function loadStories() {
const req = require.context('../src/', true, /\.stories\.tsx?$/)
req.keys().forEach((filename) => req(filename))
}
configure(loadStories, module);
I also tried changing the build-storybook command in my package.json to force increase the memory, but that doesn’t seem to work either.
"build-storybook": "npx --max_old_space_size=16384 build-storybook"
My full package.json
{
"name": "some-package",
"version": "0.0.1",
"description": "PackageDescription",
"registry": "https://myurl.com/",
"main": "dist/charts.js",
"types": "dist/charts.d.ts",
"license": "ISC",
"engines": {
"node": ">=8.*",
"yarn": ">=1.*"
},
"scripts": {
"auth": "npx vsts-npm-auth -config .npmrc",
"dev": "webpack --mode=development",
"dev:watch": "webpack --mode=development --watch",
"build": "webpack --mode=production",
"lint": "tslint ./src/**/*.{ts,tsx}",
"fix_coverage": "node ./fix_coverage.js",
"test": "yarn lint && jest --coverage",
"test:watch": "yarn lint && jest --watch",
"test:watchAll": "yarn lint && jest --watchAll",
"storybook": "start-storybook -p 6006",
"build-storybook": "npx --max_old_space_size=16384 build-storybook"
},
"dependencies": {
"json5": "^2.1.0",
"lodash": "4.17.11",
"moment": "^2.24.0",
"react-localization": "^1.0.13",
"react-select": "^2.3.0",
"react-split-pane": "0.1.77",
"sinon": "^7.2.3",
"ts-mock-imports": "^1.2.2"
},
"peerDependencies": {
"office-ui-fabric-react": "6.*",
"plotly.js": "1.*",
"react": "16.*",
"react-dom": "16.*",
"react-localization": "^1.0.13",
"react-plotly.js": "2.*",
"uuid": "^3.3.2"
},
"devDependencies": {
"@babel/core": "7.1.6",
"@storybook/addon-knobs": "4.1.16",
"@storybook/addon-options": "4.1.16",
"@storybook/addon-storysource": "4.1.16",
"@storybook/react": "4.1.16",
"@types/enzyme": "^3.1.15",
"@types/jest": "^23.3.10",
"@types/lodash": "4.14.118",
"@types/plotly.js": "1.41.0",
"@types/react": "16.7.9",
"@types/react-dom": "16.0.11",
"@types/react-plotly.js": "2.2.2",
"@types/react-select": "^2.0.11",
"@types/storybook__addon-knobs": "4.0.4",
"@types/storybook__react": "4.0.1",
"@types/uuid": "^3.4.4",
"babel-loader": "8.0.4",
"clean-webpack-plugin": "1.0.0",
"css-loader": "^2.1.0",
"dts-bundle-webpack": "1.0.1",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"enzyme-to-json": "^3.3.5",
"fork-ts-checker-webpack-plugin": "0.5.0",
"fs-jetpack": "2.2.0",
"gulp-jest": "^4.0.2",
"identity-obj-proxy": "^3.0.0",
"inline-css": "2.4.1",
"jest": "^23.6.0",
"jest-canvas-mock": "^1.1.0",
"jest-cli": "^24.1.0",
"jest-junit": "5.2.0",
"net": "^1.0.2",
"node-sass": "^4.11.0",
"office-ui-fabric-react": "6.158.0",
"plotly.js": "^1.44.4",
"react": "16.6.3",
"react-dom": "16.6.3",
"react-plotly.js": "2.2.0",
"sass-loader": "^7.1.0",
"source-map-loader": "0.2.4",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.3",
"tls": "^0.0.1",
"ts-jest": "23.10.5",
"ts-loader": "5.3.1",
"tslint": "5.11.0",
"tslint-config-prettier": "1.17.0",
"tslint-react": "3.6.0",
"typescript": "3.2.1",
"webpack": "4.29.6",
"webpack-cli": "3.3.0"
}
}
System:
- OS: Windows 10
- Device: HP Desktop
- Browser: Chrome
- Framework: React
- Addons: @storybook/addon-knobs, @storybook/addon-options, @storybook/addon-storysource
- Version: 4.1.16
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 18
- Comments: 65 (14 by maintainers)
Commits related to this issue
- CI: Attempt to claim more memory for building storybook - https://github.com/storybookjs/storybook/issues/6408 — committed to LabKey/labkey-ui-components by labkey-nicka 4 years ago
- Fix: build-storybook heap out of memery 이슈를 해결한다 * 웹팩 설정에서 minify 안하도록 처리 * https://github.com/storybookjs/storybook/issues/6408#issuecomment-648197797 * .gitignore에 sotrybook 빌드 폴더 포함 안되도록 처리 — committed to mash-up-kr/mash-up-admin-fe by dididy 2 years ago
- test: optimize memory usage when building storybook by using swc (#22975) Building storybook in CI seems to fail often -- probably due to running out of memory. Changing the compiler to swc might hel... — committed to MetaMask/metamask-extension by davidmurdoch 5 months ago
This error is still popping up for me using version
6.5.12Storybook as a component gallery is an amazing project and then we’re here: developers struggling to take the most of this beautiful tool due to bundling size optimization issues - bundling that is not even needed in many scenarios.
Why is bundling such an important thing for a project like Storybook that mainly targets internal audience? A very successful web app with 1 million daily users will share their components in Storybook with all their users? I don’t think so.
It’s very likely only devs, product owners, managers, designers, UX/UI teams will need to interact with a Storybook instance. How big can an internal team like that be? 500 (five hundred) people in a really big enterprise? And how many of them will be interacting with Storybook from a slow internet connection? I can’t say, but it seems to me that will actually be an edge case.
In a scenario with up to 500 Storybook users is all this out-of-the-box optimization really worth it?
Sorry, I’m completely new to this project and don’t mean to be critical, just putting this as food for thought. I hope it’s taken as some opportunity for improvement rather than as a negative feedback.
I was digging on this error, and what I found was that I was using this
PropTypes.arrayOf()on one of my components, after change it toPropTypes.arrayOf([])it worked again. 😕Hey @ndelangen ! Thanks for the invite! Not sure if l’ll be able to make it to the roadmap meeting but I’ll try to attend.
In the meantime, for those still facing this same issue when building Storybook, I share below the minimal config changes that I came up with on my
.storybook/main.jsto disable bundling:After applying these changes the error message
92% chunk asset optimization TerserPluginno longer appeared. I’ve built/deployed on the same remote servers a few dozens of times in the past week, successfully.Some numbers that might be helpful:
My web server: I downgraded to an AWS EC2
t2.microinstance as my build server + web server: 1 GB RAM + 1 GB swap disk space.Build time - with bundling off: Build is taking 2 to 3 minutes to complete, which for my team is totally acceptable.
Final assets size:
main*.bundle.js~ 11 MBvendor*.bundle.js~ 2 MB Total page size: 14 MB (according to Firefox 77)Page load time: About 5 minutes to load Storybook on the browser. I know, it’s not great - but it’s working fine for my team. Also, as I’m serving Storybook as a Node.js app from a very small/cheap cloud server instance, I think it’s ok. Load it, go grab a coffee and then it’ll be available offline and cached in the browser. 😃
Hope this helps other Storybook users on deciding whether disabling bundling might be an option for them or not.
I want to reopen this issue
Describe the bug I got the exact same issue like @yuanstanley in version 5.3.13 of storybook. Updateing to the newest version does not help. So it’s really the same issue. The
build-storybookcommand stops at 92% while doing stuff in theTerserPlugin.thre strange part for me is, that the build run previous without problems. But from one day to the next it does not work anymore. My collegues run on the same OS, the exact same version of storybook (same package lockfile) but do not run into the issue.
Here the full error:
To Reproduce run
yarn build-storybookExpected behavior The build shouldn’t fail.
Screenshots nothing
Code snippets on request
System: Environment Info:
System: OS: macOS 10.15.4 CPU: (8) x64 Intel® Core™ i5-8259U CPU @ 2.30GHz Binaries: Node: 10.20.1 - ~/.nvm/versions/node/v10.20.1/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.11.3 - ~/Projects/a-dir/node_modules/.bin/npm Browsers: Chrome: 83.0.4103.61 Firefox: 76.0.1 Safari: 13.1
Framework: React
Additional context I tried the following to solve the problem:
npx --max_old_space_size=16384 build-storybookAll of that does not solve the error.
Same error here with Storybook
v5.3.18andnode v12.18.0. Running on an almost empty 4 GB RAM AWS EC2 instance (onlynginxrunning) dedicated to build Storybook for a ReactJs web app with ~30 components and 5 pages. 😦Using
NODE_OPTIONSas suggested in other comments, the task seems to never finish (I waited for only one hour):Question: Could anyone please guide me on how to tell Storybook to not optimize, not minify, not use source maps, etc?
I went to the Storybook docs on customizing webpack but couldn’t even find the words
optimize,minify,source maps, and all other keywords that come to my mind.As I really don’t want to become a Webpack expert and I don’t need any fancy bundling or any other optimization, I just need to get Storybook to work and be served as a static HTML site. If it’s not minified, if it’s not bundled but it’s working that would be cool and perhaps all I’ll ever need.
Please let me know what should I change to serve Storybook the simplest possible way and no longer be stuck at the
92% chunk asset optimization TerserPluginbuilding stage.Thanks in advance for any advice!
Hey everyone.
I had the same problem with our build: Node: v10.15.3 Storybook: v5.3.18 (A bit old, so might not work for everyone) Error occurred on the following step:
93% ...set optimization ...MapDevToolPlugin ...23e40.bundle.js generate SourceMapIt looks like
TerserPluginhas some problems handling ridiculously large files. In my case we only had 2 js bundles for all of our stories (hundreds). Onejsfile was over 60MB, the other over 20MB. When storybook passed these files toTerserPluginit couldn’t produce the sourcemaps for them, even with 6GB of memory 😮.The solution for us is as follows.
This also allows you to run storybook with
cross-env analyze=trueto see your bundles after webpack has run. In order to run this you will need to increase your memory size, in the example below I have 2GB set but you might need 8GB or more.Once the analyzer is done it will open a webpage, if you see bundles larger than a few MB you might want to try this fix out.
Could you try:
or increase the number to more?
Currently also having this issue in 7.0.7
Same in
6.5.15. Any update on this?@bismarkhenao did the same mistake (
PropTypes.arrayOf()without values), had the same OOM and it got fixed once I correctedarrayOfusage. Thanks for the hint, I could have search elsewhere for a while. In other words, for me the problem wasn’t storybook but my lack of focus 😄I’ve tried the workaround above and disabling the source maps and I have this issue in 7.0.7
Problem solved with this version : https://github.com/storybookjs/storybook/releases/tag/v6.3.11
Is there any update on this issue?
Thanks for following up @yuanstanley – glad it’s working for you!
same result in 7.0.22. Tried running with 4GB on aws amplify but no luck
same result in 7.0.22. Tried running with 4GB but no luck
I’m dealing with the same problem. Running
NODE_OPTIONS=--max_old_space_size=4096 yarn storybookbypasses this error and storybook launches successfully. However, as soon as I click anything in storybook, I getmaximum call stack size exceeded error.@ndelangen I tried your earlier tip
NODE_OPTIONS=--max_old_space_size=4096 build-storybookand that worked for me, at least for now.Hmm, it’s failing for me even on Node 12. Getting that same error:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Same issue here on a 4GB self-hosted runner on Github Actions. Killed with status 137 (OOM) seemingly at random on some jobs. Using the
@storybook/nextjsframeworkas this is a Next.js project. Using version7.6.10forstorybookand related@storybook/...addons.Other jobs in the same workflow like tests, docker builds, deployments, compilation, etc., are all fine on that same runner so I’d rather not bump up to a larger one just for the sake of getting Storybook to build.
Changing the framework as suggested here seemed to yield reliable builds for the time being at least 🤞
edit: unfortunately,
swcmeans I no longer use babel, which means I can’t useidInterpolationPatternfor format js, and so I had to turn offuseSwcagain 🥀 https://github.com/storybookjs/storybook/discussions/25772In my case, I had a few big files.
Locally, it worked for me, so the failure only happened on GitHub actions nodes. To replicate the issue, I modified the command as follows:
The fix for me was to reduce a JSON file used for providing demo data for one of the stories and then the files got smaller.
In any case, @ndelangen , here’s our repository if you want a reproduction example: https://github.com/KaotoIO/kaoto-next/
Hope this gets fixed or at least we have a workaround for it by then. I feel like the code splitting might be a bit too agressive with
storyStoreV7: falseand it is not providing us the best results when it comes to building storybook and deploying it. At least that is what I understand from what is going on.Maybe we would need to split our monorepo’s storybook into sub storybooks and unify all of them with storybook composition, but it feels like a regression.
@juanigalan91 maybe this is something you might want to try: https://github.com/storybookjs/storybook/blob/868120a59e1985c834791cf72f467bc6251d5f13/docs/snippets/common/main-config-framework-options-builder-use-swc.js.mdx#L1-L16
It’s an experimental option to switch from
babeltoswc, and will also switch toTerserWebpackPlugin.swcMinify.Does someone have a repro I could use for an experiment?
I wonder if replacing Terser with esbuild would fix this problem.
Same 7.0.8
Maybe to add a little more information. I have the same memory leak issue when running
start-storybook.Storybook Version: 5.3.18 Angular Version: 8.1.2 Node Version: 12.16.1
I too am facing this issue. Any updates ?
I did try 4096 and it still failed. I tried 8192 and it just never finished. I suppose I should try spliiting things into layers, maybe the polyfills for IE.
The quickfix for me was to use the node version 12.x instead of 10.x . I don’t know why, but this solves the problem for me at the moment.
If I switch back to 10, it is still failing 🤷♀️