Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 5 upgrade #9216

Closed
EdenTurgeman opened this issue Dec 21, 2019 · 158 comments
Closed

Webpack 5 upgrade #9216

EdenTurgeman opened this issue Dec 21, 2019 · 158 comments

Comments

@EdenTurgeman
Copy link

With webpack 5 reaching it's final stages, I would love to put this on the roadmap since there is much to be gained with the new upgrade.

@shilman
Copy link
Member

shilman commented Dec 22, 2019

@EdenTurgeman is there an ETA? We're planning for 6.0 right now and it would be convenient if we could make this line up.

cc @ndelangen

@stale stale bot added the inactive label Jan 12, 2020
@storybookjs storybookjs deleted a comment from stale bot Jan 12, 2020
@stale stale bot removed the inactive label Jan 12, 2020
@shilman shilman added the todo label Jan 12, 2020
@kirill-konshin
Copy link

It looks like everything is quite smooth now, in my case we use lots of webpack plugins, all of them are updated to support webpack 5 at this moment.

@shilman
Copy link
Member

shilman commented Apr 18, 2020

@kirill-konshin thanks so much for the update. can you share a list of plugins you're using successfully?

ultimately we'll want to make a coordinated move with the rest of the ecosystem (CRA, gatsby, next, etc), but it's good to know where things stand on the plugin front, which is a more fundamental prerequisite for the move.

@kirill-konshin
Copy link

@shilman makes sense. Here's our list:

 {
   "autoprefixer": "9.7.6",
    "case-sensitive-paths-webpack-plugin": "2.3.0",
    "circular-dependency-plugin": "5.2.0",
    "clean-webpack-plugin": "3.0.0",
    "css-loader": "3.5.2",
    "cssnano": "4.1.10",
    "cssnano-preset-advanced": "4.0.7",
    "duplicate-package-checker-webpack-plugin": "3.0.0",
    "fast-async": "6.3.8",
    "fast-sass-loader": "1.5.0",
    "file-loader": "6.0.0",
    "fork-ts-checker-webpack-plugin": "4.1.3",
    "html-webpack-plugin": "4.2.0",
    "mini-css-extract-plugin": "0.9.0",
    "postcss-flexbugs-fixes": "4.2.0",
    "postcss-loader": "3.0.0",
    "speed-measure-webpack-plugin": "1.3.3",
    "stats-webpack-plugin": "0.7.0",
    "style-loader": "1.1.4",
    "ts-loader": "7.0.0",
    "url-loader": "4.1.0",
    "webpack": "5.0.0-beta.13",
    "webpack-bundle-analyzer": "3.7.0",
    "webpack-cli": "3.3.11",
    "webpack-dev-server": "3.10.3",
    "webpack-manifest-plugin": "3.0.0-rc.0",
    "webpack-merge": "4.2.2"
}

@EdenTurgeman
Copy link
Author

@kirill-konshin @shilman Is there a specific way you set it up to work with the 6.0.0.alpha? Seems like when I start a fresh storybook html-webpack-plugin refuses to start up.

/****Project name *****/node_modules/@storybook/core/node_modules/html-webpack-plugin/node_modules/webpack/lib/ExternalModuleFactoryPlugin.js:29
                normalModuleFactory.hooks.factorize.tapAsync(
                                                    ^

TypeError: Cannot read property 'tapAsync' of undefined

@kirill-konshin
Copy link

@EdenTurgeman it does not work with Storybook, that's the whole point ))) I have Webpack 5 based setup and I have to stick to Webpack 4 in Storybook...

@shilman it would be great if someone could publish a beta version of storybook with at least initial support of Webpack 5. In this case I can provide some testing.

@shilman shilman modified the milestones: 6.0, 7.0 Apr 22, 2020
@shilman
Copy link
Member

shilman commented Apr 22, 2020

@kirill-konshin Given the state of things this will most likely wind up as a 7.0 breaking change. We'll post here once there's a testable alpha, but don't hold your breath.

@kirill-konshin
Copy link

@shilman makes sense. Anyway, if you can publish something like an early beta of it, I'll do my best to help.

@shilman
Copy link
Member

shilman commented Apr 23, 2020

Thanks @kirill-konshin!! Much appreciated 🙏🙏🙏

@7rulnik
Copy link
Contributor

7rulnik commented Jun 25, 2020

I will take it. Let's see how difficult it will be :)

@shilman
Copy link
Member

shilman commented Jun 26, 2020

@7rulnik awesome!!! i think @ndelangen has also started looking at this

@ndelangen
Copy link
Member

I did a pair programming session last week with @ScriptedAlchemy

We did a bunch of the work to upgrade to webpack 5, but we didn't quite finish.
Here's our WIP branch: origin/tech/webpack5

@7rulnik
Copy link
Contributor

7rulnik commented Jun 26, 2020

Could you open WIP pr so we can track progress?

@ndelangen
Copy link
Member

Certainly:
#11326

@daveisfera
Copy link

With webpack 5 being officially released soon, is this worth picking up and getting over the finish line so we can also get support for node 14 that will be reaching LTS soon as well?

@ndelangen
Copy link
Member

@daveisfera yes it is, but we just released v6.

A webpack is likely going to be a major breaking change so it'd require us to do a major version bump too.
And this PR is pretty far of from being ready.

If you'd be able to offer your help, that'd be very very welcome!

@ntucker
Copy link

ntucker commented Feb 25, 2021

@ntucker here's the error I get when running your repro

ERR! Error: Cannot find module '/Users/shilman/projects/testing/anansi/node_modules/@anansi/webpack-config/lib/index.js'. Please verify that the package.json has a valid "main" entry
ERR!     at tryPackage (node:internal/modules/cjs/loader:327:19)
ERR!     at Function.Module._findPath (node:internal/modules/cjs/loader:540:18)
ERR!     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:887:27)
ERR!     at Function.Module._load (node:internal/modules/cjs/loader:745:27)
ERR!     at Module.require (node:internal/modules/cjs/loader:972:19)
ERR!     at require (node:internal/modules/cjs/helpers:88:18)
ERR!     at Object.<anonymous> (/Users/shilman/projects/testing/anansi/examples/typescript/.storybook/webpack.config.js:1:42)

Oops, forgot you need to build that first. Yarn build from root before you change directory

@kirill-konshin
Copy link

@shilman ive got a bad error JetBrains/svg-sprite-loader#435 since storybook/react uses wp4 and my loader wants wp5 (as it’s installed from my dependencies) I’ve got a resolution conflict... I really find it a bad idea to keep using wp4 and wp5 simultaneously...

@pc-vmora
Copy link

pc-vmora commented Mar 3, 2021

Hi @shamin I get the following error when I run start-stoybook

Error: module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)
at ProvidedDependency.set (project-path/node_modules/webpack/lib/Dependency.js:220:9)
at iterationDependencies (project-path/node_modules/@storybook/core/node_modules/webpack/lib/Compilation.js:940:21)
at project-path/node_modules/@storybook/core/node_modules/webpack/lib/Compilation.js:950:8
at project-path/node_modules/@storybook/core/node_modules/webpack/lib/NormalModuleFactory.js:409:6
at project-path/node_modules/@storybook/core/node_modules/webpack/lib/NormalModuleFactory.js:155:13
at eval (eval at create (project-path/node_modules/tapable/lib/HookCodeFactory.js:33:10), :14:1)
at project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:178:9
at project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:125:7
at project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:125:7
at project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:125:7
at CaseSensitivePathsPlugin.fileExistsWithCase (project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:95:5)
at project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:118:10
at CaseSensitivePathsPlugin.getFilenamesInDir (project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:52:5)
at CaseSensitivePathsPlugin.fileExistsWithCase (project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:101:8)
at project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:118:10
at Array. (project-path/node_modules/case-sensitive-paths-webpack-plugin/index.js:72:5)

@shilman
Copy link
Member

shilman commented Mar 3, 2021

@pc-vmora Do you have a repro repo you can share?

@pc-vmora
Copy link

pc-vmora commented Mar 4, 2021

@shilman it's a private repo.

@targumon
Copy link

I saw that v6.2.0-rc.0 was released today.
Gave it a go in my existing Webpack 5 project.
Followed @shilman 's instructions (upgrade installation, add builder-webpack5, update main.js, disable all addons).

Unfortunately not only I'm still hit with 'compilation' argument must be an instance of Compilation error while trying to build-storybook, now I can't even start-storybook (because of __webpack_base_uri__ is not defined error at @storybook/core-common/dist/cjs/templates/index.ejs:76)

@jantimon wrote earlier that html-Webpack-Plugin 5.0.0 should pickup the correct webpack, and builder-webpack5 seems to use that version, so I'm not even sure what's the next step here.

@alexander-akait
Copy link

@targumon What is version of mini-css-extract-plugin?

@targumon
Copy link

I'm not using mini-css-extract-plugin, not directly at least.
html-webpack-plugin lists version 1.0.0 of it in its devDependencies, if that what you meant.

@ntucker
Copy link

ntucker commented Mar 31, 2021

I was looking into this and I found out why @pmmmwh/react-refresh-webpack-plugin was detect webpack 4. For some reason when storybook is installed, it has webpack 4 under @pmmmwh/react-refresh-webpack-plugin own node_modules folder. Not sure why this is. Using yarn 1.

@targumon
Copy link

targumon commented Apr 5, 2021

In continuation to my comment from a few weeks ago - I ran npm ls html-webpack-plugin and got this:

├─┬ @storybook/builder-webpack5@6.2.3
│ └── html-webpack-plugin@5.3.1  deduped
├─┬ @storybook/react@6.2.3
│ └─┬ @storybook/core@6.2.3
│   └─┬ @storybook/core-server@6.2.3
│     └── html-webpack-plugin@4.5.2 ⬅ 🤔 
└── html-webpack-plugin@5.3.1 

Is this the expected output? does the compilation error exist due to the old html-webpack-plugin still being used under the hood?

@ja0n
Copy link

ja0n commented May 8, 2021

@targumon for 'compilation' argument must be an instance of Compilation I needed to enforce terser-webpack-plugin >= 5.0.0 (which drops support for webpack@4):
npm install -D terser-webpack-plugin@5.1.1

Now I'm having this same __webpack_base_uri__ is not defined error
I think it's related to node@14 and ESM, as it runs in strict mode, which throws on undefined variable assignment.
Then the problem is for some reason __webpack_base_uri__ is not defined, while __webpack_public_path__ is fine.

I made a change to html-webpack-plugin/lib/child-compiler.js, prepending global, and was able to run build-storybook

- new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
+ new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = global.__webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);

@alexander-akait
Copy link

@ja0n run yarn why webpack, it looks you have old version of v5, need update

@rodoabad
Copy link

rodoabad commented Jul 1, 2021

I'm also getting a similar error.

manager (webpack 5.15.0) compiled with 1 error in 31587 ms
webpack built preview 52b52a5bee4b356f394e in 40476ms
  Error: __webpack_base_uri__ is not defined
  
  - index.ejs:76 Object.data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;
    [component-library]/[@storybook]/core-common/dist/cjs/templates/index.ejs:76:46
  
  - index.ejs:99 __webpack_require__
    [component-library]/[@storybook]/core-common/dist/cjs/templates/index.ejs:99:41
  
  - index.ejs:115 
    [component-library]/[@storybook]/core-common/dist/cjs/templates/index.ejs:115:11
  
  - index.ejs:117 
    [component-library]/[@storybook]/core-common/dist/cjs/templates/index.ejs:117:12
  
  - index.js:142 HtmlWebpackPlugin.evaluateCompilationResult
    [component-library]/[builder-webpack5]/[html-webpack-plugin]/index.js:142:28
  
  - index.js:324 
    [component-library]/[builder-webpack5]/[html-webpack-plugin]/index.js:324:26
  
  - runMicrotasks
  
  - task_queues.js:95 processTicksAndRejections
    internal/process/task_queues.js:95:5
  
  - async Promise.all

@alexander-akait
Copy link

Update html-webpack-plugin, you still use old version

@targumon
Copy link

targumon commented Jul 1, 2021

@alexander-akait see my comment from Apr 5.
It doesn't matter what version of html-webpack-plugin you use, if storybook/core is using an outdated one internally.

@alexander-akait
Copy link

@targumon somebody should update this plugin...

@shilman
Copy link
Member

shilman commented Jul 2, 2021

@targumon @alexander-akait we are on the latest version AFAIK, so if it's running an older version it could either be due to (1) a misconfiguration in your project, (2) an outdated version in your lockfile, or (3) a hoisting issue:

"html-webpack-plugin": "^5.0.0",

I revamped webpack5 support in 6.3, so if you haven't upgraded that might help:

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5-manager-build

@rodoabad
Copy link

rodoabad commented Jul 6, 2021

This is what I have right now (thanks, Renovate!)

    "@storybook/addon-a11y": "6.3.2",
    "@storybook/addon-actions": "6.3.2",
    "@storybook/addon-backgrounds": "6.3.2",
    "@storybook/addon-console": "1.2.3",
    "@storybook/addon-controls": "6.3.2",
    "@storybook/addon-docs": "6.3.2",
    "@storybook/addon-knobs": "6.2.9",
    "@storybook/addon-viewport": "6.3.2",
    "@storybook/addons": "6.3.2",
    "@storybook/api": "6.3.2",
    "@storybook/builder-webpack5": "6.3.2",
    "@storybook/client-api": "6.3.2",
    "@storybook/components": "6.3.2",
    "@storybook/manager-webpack5": "6.3.2",
    "@storybook/react": "6.3.2",
    "@storybook/storybook-deployer": "2.8.10",
    "@storybook/theming": "6.3.2",

Screen Shot 2021-07-06 at 10 23 07 AM

I'm going to delete my lock file and update this post if it fixes the issue.

After deleting the lock file...

Screen Shot 2021-07-06 at 10 28 45 AM

@aladdin-add
Copy link

it does not make sense to force users installing both webpack v4 & webpack v5 - maybe this can be reopened?

@ScriptedAlchemy
Copy link

Agreed 👆

@FezVrasta
Copy link
Contributor

I keep getting the Error: __webpack_base_uri__ is not defined with html-webpack-plugin@5.5.0 and Storybook 6.4.9, what am I missing?

@shilman
Copy link
Member

shilman commented Jan 5, 2022

@aladdin-add @ScriptedAlchemy the plan is to have the user explicitly install a builder (webpack4 or webpack5 or something else like vite) and use that, so that there is only one builder installed. unfortunately this is a breaking change, so we can't do it until 7.0, and in the meantime we are in this ugly (but workable, IMO) situation.

@aladdin-add
Copy link

In some rare cases it could cause issues - especially when using npm/yarn (as they will flatten the deps). an example:

info Reasons this module exists
   - "@storybook#addon-docs#@storybook#builder-webpack4" depends on it
   - Hoisted from "@storybook#addon-docs#@storybook#builder-webpack4#css-loader#postcss"
   - Hoisted from "@storybook#addon-docs#@storybook#builder-webpack4#css-loader#postcss-modules-local-by-default#postcss"
   - Hoisted from "@storybook#addon-docs#@storybook#builder-webpack4#css-loader#postcss-modules-extract-imports#postcss"
   - Hoisted from "@storybook#addon-docs#@storybook#builder-webpack4#css-loader#postcss-modules-scope#postcss"
   - Hoisted from "@storybook#addon-docs#@storybook#builder-webpack4#css-loader#postcss-modules-values#postcss"

it brings postcss v7, not compat with a few plugins - which breaks our building tool. a workaround is to add postcss v8 in the devDependencies. ╭(╯^╰)╮

@shilman
Copy link
Member

shilman commented Jan 5, 2022

@aladdin-add I'd say that these cases are unfortunately not that rare. 😭 But that's the reality of the npm ecosystem at this point in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests