storybook: Module not found: Error: Can't resolve 'util'
Describe the bug With a fresh build of storybook using react, webpack 5 and yarn PnP, I get an error during build:
ERR! => Failed to build the manager
ERR! Module not found: Error: Can't resolve 'util' in '***/storybook-repro-1/.yarn/__virtual__/@storybook-ui-virtual-0f4525ad5e/4/.yarn/berry/cache/@storybook-ui-npm-6.5.5-c5b3ce8d48-8.zip/node_modules/@storybook/ui/dist/esm'
ERR!
ERR! BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
ERR! This is no longer the case. Verify if you need this module and configure a polyfill for it.
ERR!
ERR! If you want to include a polyfill, you need to:
ERR! - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
ERR! - install 'util'
ERR! If you don't want to include a polyfill, you can use an empty module like this:
ERR! resolve.fallback: { "util": false }
To Reproduce Simple repro repository
All I did was:
yarn dlx sb@next repro --pnp- Choose
reactandreact-typescript yarn add -D webpack @storybook/builder-webpack5 @storybook/manager-webpack5- Change
main.tsto include{ "core": { "builder": "webpack5" } } - Run
yarn build-storybook
System
Environment Info:
System:
OS: macOS 12.4
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Binaries:
Node: 16.14.2 - /private/var/folders/71/z4j0sg3j26l87c_6nv7y7tz00000gn/T/xfs-6d56c161/node
Yarn: 3.2.0 - /private/var/folders/71/z4j0sg3j26l87c_6nv7y7tz00000gn/T/xfs-6d56c161/yarn
npm: 8.9.0 - /usr/local/bin/npm
Browsers:
Chrome: 101.0.4951.64
Edge: 100.0.1185.50
Firefox: 100.0
Safari: 15.5
Additional context
The same project, but with node-linker: node-modules enabled does not produce the error.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 10
- Comments: 18 (5 by maintainers)
Commits related to this issue
- fix: similar issue to https://github.com/storybookjs/storybook/issues/18319 — committed to jpvalery/mistral by jpvalery 2 years ago
- fix(stories|deps): add missing sb peer dependency https://github.com/storybookjs/storybook/issues/18319 — committed to kleinweb/logan-center by montchr 2 years ago
I had the same error, i just installed util as devDependency yarn add -D util
We also got this error after changing our devDependency from @cypress/code-coverage to 3.10.0.
Before:
After update to
@cypress/code-coverage@3.10.0:What seems to work is manually install
utilas a devDependency, so it can successfully be resolved. We are also using webpack 5 instead of 4. So in our case@storybook/ui/dist/esmhas a dependency toutilsomehow which is not anymore polyfilled by webpack. Maybe this helps for further analysis?Just ran into this one on the clean install of
v7.0.0-rc.4in the Next.js project after runningnpx storybook initYo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.10-alpha.0 containing PR #18412 that references this issue. Upgrade today to the
@prereleaseNPM tag to try it out!Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-alpha.2 containing PR #18412 that references this issue. Upgrade today to the
@futureNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
I am getting the same, after trying to upgrade storybook to 6.5.5 from 6.4.21. I ran upgrade using npx sb upgrade.