storybook: storybook@6 throws a core-js error
With storybook 6, my very basic typescript setup throws errors about core-js polyfills every time.
Module not found: Error: Can't resolve 'core-js/modules/web.dom-collections.iterator'
this is thrown from ‘generated-stories-entry’. i can see earlier in the webpack output that the polyfill was built:
[./node_modules/@storybook/core/dist/server/common/polyfills.js] 120 bytes {vendors~main} [built]
which afaik is where you include core-js.
with storybook 5, this works just fine. its a clean setup from today, npm i -D @storybook/html (5 or 6) and this config:
module.exports = {
stories: ['../src/**/*.stories.ts'],
webpackFinal: (config) => {
config.module.rules.push({
test: /\.ts$/,
use: [
{loader: require.resolve('ts-loader')}
]
});
config.resolve.extensions.push('.ts');
return config;
}
};
I think this is because there are multiple core-js versions in my node_modules and storybook is resolving the wrong one (somehow). if i look at the one inside storybook’s packages, its got the right files.
this isn’t something i should have to ‘fix’ though IMO, as so many dependencies use core-js it seems like a very likely situation for many to bump into. my guess is you can fix it by installing core-js as a direct dependency but thats also far from ideal.
EDIT:
Temporary workaround
If you’ve come across this issue while searching, we do not yet have a solution merged in (this issue will close when we do). However, there is a workaround: simply install core-js@3 as a direct dependency (npm i -D core-js@3).
If that doesn’t work for you, please do comment so we are aware in case there are some other edge cases.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 63
- Comments: 73 (25 by maintainers)
Commits related to this issue
- storybook-html: fix breaking changes resulting from migration https://github.com/storybookjs/storybook/issues/11255 — committed to uq-its-ss/design-system by uqmchu 4 years ago
- storybook-html: fix breaking changes resulting from migration https://github.com/storybookjs/storybook/issues/11255 — committed to uq-its-ss/design-system by uqmchu 4 years ago
- storybook-html: fix breaking changes resulting from migration https://github.com/storybookjs/storybook/issues/11255 — committed to uq-its-ss/design-system by uqmchu 4 years ago
- storybook-html: fix breaking changes resulting from migration https://github.com/storybookjs/storybook/issues/11255 — committed to uq-its-ss/design-system by uqmchu 4 years ago
- storybook-html: fix breaking changes resulting from migration https://github.com/storybookjs/storybook/issues/11255 — committed to uq-its-ss/design-system by uqmchu 4 years ago
- storybook-html: fix breaking changes resulting from migration https://github.com/storybookjs/storybook/issues/11255 — committed to uq-its-ss/design-system by uqmchu 4 years ago
- 🐞 working version for storybook problem. https://github.com/storybookjs/storybook/issues/11255 — committed to Lincerossa/form-one by Lincerossa 4 years ago
- Upgrade to storybook 6: the config part Related issues: - Removed @babel/plugin-proposal-class-properties plugin. Not sure this is the right thing to do, I'll try to find another workaround https://g... — committed to blablacar/ui-library by deleted user 4 years ago
- Upgrade to storybook 6: the config part Related issues: - Removed @babel/plugin-proposal-class-properties plugin. Not sure this is the right thing to do, I'll try to find another workaround https://g... — committed to blablacar/ui-library by deleted user 4 years ago
- Upgrade to storybook 6: the config part Related issues: - Removed @babel/plugin-proposal-class-properties plugin. Not sure this is the right thing to do, I'll try to find another workaround storybook... — committed to blablacar/ui-library by deleted user 4 years ago
- Add core-js as a temp fix for Storybook #11255 see: https://github.com/storybookjs/storybook/issues/11255 — committed to blablacar/ui-library by pith 4 years ago
- Add core-js as a temp fix for Storybook #11255 (#982) see: https://github.com/storybookjs/storybook/issues/11255 — committed to blablacar/ui-library by pith 4 years ago
- link local dependencies: https://github.com/storybookjs/storybook/issues/11255 — committed to charkour/harmoniously by charkour 3 years ago
- Needed to add core-js as a dev dependency https://github.com/storybookjs/storybook/issues/11255 - updated component logic to use styles and updated stories - 'start-storybook' and 'build-storybook' ... — committed to kro-hub/react-ui-lib-test by deleted user 3 years ago
- Fix storybook issue when importing local modules reference: https://github.com/storybookjs/storybook/issues/11255#issuecomment-764060749 — committed to acusti/uikit by acusti 3 years ago
just a reminder that now that you published 6.0 officially, this is still a problem.
it is very awkward having to install
core-jsdirectly in each repo we use storybook for. do you have any suggested fix on your end for this? anything we can contribute to help?Zoinks!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.2.0-alpha.0 containing PR #13055 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.
For people still bumping into this, we’re blocked by babel/babel#12035
The problem is pretty well understood now and is on babel’s end of things. Workarounds may be possible but would be fairly complex and hacky so im hoping babel can just fix it on their end instead, or at least tell us how to.
Looks like that is being fixed at babel/babel-polyfills#40
edit:
this is being worked on in #13055
Simply install
core-jsdependecynpm i core-jsI can confirm the solution of @jefferscn . I simplified with this, but it is the same:
config.resolve.alias['core-js/modules'] = '@storybook/core/node_modules/core-js/modules'Adding code upside to main.js sovle my problem.
Also having this problem.
Based on https://github.com/storybookjs/storybook/issues/6204#issuecomment-478992364, I added this to my config and it’s resolving correctly now:
Note that this is pointing to the root
node_modules/core-jsfolder in my project, not to one that’s bundled with anything else.Can this be updated when it’s fully released?
@shilman Still not working for me for very weird reason. Running
yarn storybookthrows a bunch of errors about core-js polyfill. For example:I have to do the workaround in
main.jswith the following:This happens when I have
core-jsversion specifically points to 2.6.9.Problem for me was that I didn’t match the
@babel/preset-envoptioncorejsproperty version to the correct one.package.json:
"core-js": "^3.6.5",The solution: .babelrc (or wherever your babel config lives)
Hey, thanks for the continued work on this. Unfortunately, upgrading to
6.2.0-alpha.1on a private repo didn’t fix the stories, we didn’t have any workarounds to remove. I’ll update here if I come up with a minimal repo that contains the issue.The repository is a mix of JS/typescript, managed by yarn 2 (berry), and has core-js version
3.0.1specified at the root levelpackage.json. Most of the errors are of the formI had to modify my
.storybook/main.jsfile to:same got a bunch of error like
Module not found: Error: Can't resolve 'core-js/modules/web.dom-collections.iterator'Module not found: Error: Can't resolve 'core-js/modules/es.symbol.iterator'That workaround didn’t work for me, I needed to configure specific aliases in the main.js file for core-js modules with name conflicts:
Same here. Just set up a clean project with vue-cli, added storybook and storybook-docs.
npm run storybookresults in lots ofModule not found: Error: Can't resolve 'core-js/modules/....Also, I found another workaround: when using yarn pnp + workspaces, if
core-jsis available in the top level module but not in a sub-package, adding this line in the main.js file should work:(
require.resolve("core-js")will return the path to the.../node-modules/core-js/index.jsfile in pnp, and thenpath.dirname(...)will return the path to core-js itself and thus whencore-js/modulewill be required, it’ll indeed generate.../node-modules/core-js/moduleand not.../node-modules/core-js/index.js/module)Good news update on https://github.com/storybookjs/storybook/issues/11255#issuecomment-741905199
I investigated this bug with @arcanis, who quickly identified the issue. We found the error was due to the fact that a dependency of the main application (the one using storybook) was in a separate yarn workspace that did not have
core-jsexplicitly specified as a dependency.Adding the same version of
core-jsas a dependency to that library workspace as the version in the main application (the one where storybook is explicitly used) fixes the issue (usingStorybook 6.0.21).Still broken.
similar issue, I already had core-js in my project, and upgrading to 3(which we’ve been meaning to do anyway) doesn’t seem to fix this issue.
I originally wrote https://github.com/ndelangen/corejs-upgrade-webpack-plugin to ‘solve’ this issue.
But I deprecated it, because it just adds other problems, see: https://github.com/storybookjs/storybook/issues/7445 and https://github.com/ndelangen/corejs-upgrade-webpack-plugin/issues/7
conflicting versions of corejs are the bane of my existence.
essentially, storybook’s generated output tries to require
core-jsfor various polyfills.im guessing because it is generated output and doesn’t “live” in the storybook directory (
node_modules/@storybook), it will resolve the first available core-js from the top level rather than resolving it relative to storybook’s directory.so if you have storybook in a project which already has a different version of core-js (not necessarily as a direct dependency, all sorts of other projects also depend on core-js), that one may be required by accident rather than the one storybook wants.
this means the paths fail to resolve if the two core-js versions are drastically different.
the workaround (
npm i -D core-js) solves the problem because then your top-level core-js is the same version as the one storybook wants. the older version will have then been moved deeper to live alongside whatever was requiring it.I have the same problem with you. You can try to add the option corejs: 3 with @babel/preset-env config in your .babelrc file and this works for me.
dirnamewas the magic I needed, thanks!the previous problem with
__webpack_require__feels like its another issue.somehow the webpack overrides conflicting maybe, its difficult to reproduce that one for sure. @uriklar if you could throw together a test repo which reproduces that problem, that’d be a big help. a minimal reproduction, trying to strip away as much as you can without making the problem go away.
same for you @henriquez , if you can reproduce it in a repo somewhere we can try debug a bit
This release has finally fixed it for our component library’s Storybook - thanks!
@shilman I just upgraded my Ember Addon with the pre-release version and it all works!
I was able to fix this by adding
to my
package.json, as described in #8267.I was running into this problem on 6, downgraded to 5.3, hit another version of this issue after a while, then found & implemented the fix. I figured I might as well try the upgrade back to 6, and thankfully it still works.
All of the responses to add fields to the Webpack config did not work for me, but this obviously did.
I’m using Gatsby, and evidently there is one core-js@^2.4.0 dependency buried deep inside:
npm ls core-jsAdding the
resolutionsfield does technically break the core-js dependency for that Gatsby / babel-runtime dependency (the tree now saysUNMET DEPENDENCYnext to core-js@^2.4.0), but I haven’t seen an issue yet.no worries ill get on discord soon, wasn’t aware there was a storybook one 👍
@43081j happy to chat about a solution to this, are you on the storybook discord? https://discord.gg/7yKH3EU
I have the same problem. I set a breakpoint on the webpackFinal method, but it did not trigger. I suspect that the change here caused this problem, which was good before 6.0.0 beta14.