storybook: Webpack.IgnorePlugin() Error with Webpack 5 and React < 18
Describe the bug
Tried updating the webpack from 4 to 5 but still have to use React 16.14.0. Added both @storybook/builder-webpack5 and @storybook/manager-webpack5 but getting an error from webpack because of how framework-preset-react-dom-hack.js is using webpack.IgnorePlugin().
Error:
Error: NormalModuleFactory.beforeResolve (IgnorePlugin) is no longer a waterfall hook, but a bailing hook instead. Do not return the passed object, but modify it instead. Returning false will ignore the request and results in no module created.
To Reproduce Set the package as below:
{
"devDependencies": {
"@storybook/addon-a11y": "^6.5.9",
"@storybook/addon-actions": "^6.5.9",
"@storybook/addon-essentials": "^6.5.9",
"@storybook/addon-interactions": "^6.5.9",
"@storybook/addon-links": "^6.5.9",
"@storybook/builder-webpack5": "^6.5.9",
"@storybook/manager-webpack5": "^6.5.9",
"@storybook/react": "^6.5.9",
"@storybook/testing-library": "^0.0.13",
...
...
"webpack": "^5.73.0",
},
"dependencies": {
...
"react": "^16.14.0",
"react-dom": "^16.14.0",
...
}
}
and here is the main.js file:
module.exports = {
core: {
builder: "webpack5"
},
stories: ["../stories/**/*.stories.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"@storybook/addon-a11y"
],
framework: "@storybook/react"
};
System System: OS: macOS 12.4 CPU: (10) arm64 Apple M1 Pro Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Browsers: Chrome: 97.0.4692.99 Firefox: 101.0 Safari: 15.5 npmPackages: @storybook/addon-a11y: ^6.5.9 => 6.5.9 @storybook/addon-actions: ^6.5.9 => 6.5.9 @storybook/addon-essentials: ^6.5.9 => 6.5.9 @storybook/addon-interactions: ^6.5.9 => 6.5.9 @storybook/addon-links: ^6.5.9 => 6.5.9 @storybook/builder-webpack5: ^6.5.9 => 6.5.9 @storybook/manager-webpack5: ^6.5.9 => 6.5.9 @storybook/react: ^6.5.9 => 6.5.9 @storybook/testing-library: ^0.0.13 => 0.0.13
Additional context
Looks like the error comes from framework-preset-react-dom-hack.js:
export async function webpackFinal(config: Configuration) {
const reactDomPkg = await readJSON(require.resolve('react-dom/package.json'));
return {
...config,
plugins: [
...config.plugins,
reactDomPkg.version.startsWith('18') || reactDomPkg.version.startsWith('0.0.0')
? null
: new IgnorePlugin({
resourceRegExp: /react-dom\/client$/,
contextRegExp: /(app\/react|app\\react|@storybook\/react|@storybook\\react)/, // TODO this needs to work for both in our MONOREPO and in the user's NODE_MODULES
}),
].filter(Boolean),
};
}
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 23
- Comments: 21 (3 by maintainers)
I’m using React 17 with webpack 5 but encountered this error when trying to upgrade storybook from 6.4.9 to 6.5.9. I’ve downgraded back to 6.4.9 in the meantime.
@hrldcpr repro demonstrates the problem (in both npm8 and npm6), thanks so much
Haven’t figured out the issue yet, but have some workarounds:
yarninstead ofnpmit worksnpm8and addoverridestopackage.jsonit works:@ShuPink This solution seems to be working as a temporary fix.
@hrldcpr
You are right. The issue was I copied the version verbatim, I should have replaced the version with the one that I am using.
The workaround WORKS. Thanks for your help!
@hrldcpr
That didn’t work. Do I have to run
npm iand regenerate the package-lock after making that change?I ran
npm ls webpackand noticed these errors too@rexkenley just in case you didn’t see it above, if you’re looking for a workaround before this gets fixed, try adding this to your
package.json:At least with core-common it explicitly defines that it uses webpack 4: https://github.com/storybookjs/storybook/blob/v6.5.12/lib/core-common/package.json#L92
I feel like this should be changed to “^4.0.0 || ^5.0.0” to allow either version. But I think that the default would be to install webpack 5 which would break the build of people not using the webpack 5 builder.
So the overrides option may be the best bet if you can use npm v8. Unfortunately my team is stuck on npm v7 & I attempted modifying the package-lock by hand to get rid of webpack 4 references but that proved to be more difficult than I hoped so I’m just going to hold back on upgrading to 6.5. Hopefully v7 will switch to webpack 5 by default
@hrldcpr Thanks so much! I’ll see what we can figure out!
Cc @storybookjs/core
Upgrading to 6.5.10 has now resolved this issue for me ^^;
My problem temporarily has been solved by using
--legacy-peer-depson the npm installation with the latest version Or addlegacy-peer-deps=truein your.npmrcfile