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

@nrwl/web:build does not work with webpack 5 #4627

Closed
ashwinGokhale opened this issue Jan 28, 2021 · 28 comments
Closed

@nrwl/web:build does not work with webpack 5 #4627

ashwinGokhale opened this issue Jan 28, 2021 · 28 comments
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@ashwinGokhale
Copy link
Contributor

ashwinGokhale commented Jan 28, 2021

Current Behavior

Running yarn nx build <project_name> with webpack@5.18.0 on a React app, gives the following error:

Unable to resolve @nrwl/web:build.
Cannot find module 'webpack/lib/dependencies/ImportDependenciesBlock'

Expected Behavior

It should successfully build the React app.

Steps to Reproduce

  1. Create nx workspace with a React app.
  2. Add resolutions to package.json:
"resolutions": {
    "webpack": "5.18.0"
}
  1. Run yarn
  2. Run yarn nx build <project_name>

Failure Logs

Here is the full error log:

Unable to resolve @nrwl/web:build.
Cannot find module 'webpack/lib/dependencies/ImportDependenciesBlock'
Require stack:
- C:\Users\user\source\project\node_modules\@nrwl\web\src\utils\third-party\cli-files\plugins\named-chunks-plugin.js
- C:\Users\user\source\project\node_modules\@nrwl\web\src\utils\third-party\cli-files\models\webpack-configs\common.js
- C:\Users\user\source\project\node_modules\@nrwl\web\src\utils\web.config.js
- C:\Users\user\source\project\node_modules\@nrwl\web\src\builders\build\build.impl.js
- C:\Users\user\source\project\node_modules\@nrwl\tao\src\shared\workspace.js
- C:\Users\user\source\project\node_modules\@nrwl\tao\src\commands\run.js
- C:\Users\user\source\project\node_modules\@nrwl\tao\index.js
- C:\Users\user\source\project\node_modules\@nrwl\cli\lib\run-cli.js

Environment

  Node : 12.18.3
  OS   : win32 x64
  yarn : 1.22.5

  nx : Not Found
  @nrwl/angular : 11.1.2
  @nrwl/cli : 11.1.2
  @nrwl/cypress : 11.1.2
  @nrwl/devkit : 11.1.2
  @nrwl/eslint-plugin-nx : 11.1.2
  @nrwl/express : 11.1.2
  @nrwl/jest : 11.1.2
  @nrwl/linter : 11.1.2
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 11.1.2
  @nrwl/react : 11.1.2
  @nrwl/schematics : Not Found
  @nrwl/tao : 11.1.2
  @nrwl/web : 11.1.2
  @nrwl/workspace : 11.1.2
  typescript : 4.1.3
@FrozenPandaz FrozenPandaz added the scope: react Issues related to React support for Nx label Jan 29, 2021
@sshakil-h2
Copy link

Are there any workarounds?

@clonardo
Copy link

+1, still looks like an issue. No easy workaround as far as I see, at a quick glance.

@ChazUK
Copy link

ChazUK commented Feb 28, 2021

I'm trying to implement the correct format of @use in SCSS with the sass-loader but that requires the latest version of Webpack :(

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Mar 29, 2021
@elenasch
Copy link

elenasch commented Apr 2, 2021

This is still very much an issue, and a blocker for us to use Nx. Would love to see it make into the tools soon

@github-actions github-actions bot removed the stale label Apr 2, 2021
@smasala
Copy link
Contributor

smasala commented Apr 23, 2021

Any updates on this? Still an issue with 12.0.8

@smasala
Copy link
Contributor

smasala commented Apr 23, 2021

One dreadful way around this is to download webpack 4 under an alias

yarn add -D webpack4@npm:webpack@4.42.0

Then add a post/uninstall script to move webpack 4

"postinstall": "mv ./node_modules/webpack4 ./node_modules/@nrwl/web/node_modules/webpack"

Then you can build the application

@Jordan-Hall
Copy link
Contributor

Jordan-Hall commented May 12, 2021

I was taking a look at this yesterday. To fix this, NX needs to upgrade the base app to Webpack 5, which will cause some issues then remove https://github.com/nrwl/nx/blob/master/packages/web/src/utils/third-party/cli-files/plugins/named-chunks-plugin.ts this file then inside the common.ts file (https://github.com/nrwl/nx/blob/master/packages/web/src/utils/third-party/cli-files/models/webpack-configs/common.ts) and make a tweak to the optimization section:

optimization: {
      noEmitOnErrors: true,
      moduleIds: 'deterministic',
      chunkIds: buildOptions.namedChunks ? 'named' : 'deterministic',
      minimizer: [
        new HashedModuleIdsPlugin(),
        // TODO: check with Mike what this feature needs.
        new BundleBudgetPlugin({ budgets: buildOptions.budgets }),
        ...extraMinimizers,
      ],
    },

But then the run-webpack.ts will also need tweaking :/ not managed to solve that issue yet. Appears one of the function doesn't return the correct type :(

@smasala
Copy link
Contributor

smasala commented May 12, 2021

@Jordan-Hall correct, they are currently incompatible. The only way round it to patch it or "trick" it by giving@nrwl/web it's own local webpack version (i.e 4).

You can either do it as stated [above(https://github.com//issues/4627#issuecomment-825797960) or you could prob do it with yarn and Selective dependency resolutions. See: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/ and https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md

For example:

"resolutions": {
    "**/@nrwl/web/webpack": "4.46.0"
  },

Obviously, this only works if your web app in your mono-repo doesn't require webpack 5 but your angular apps do for example.

@Jordan-Hall
Copy link
Contributor

Are they a reason we cant upgrade the whole of NX to Webpack 5? I don't mind carrying on working on it due to a requirement for a client.

@smasala
Copy link
Contributor

smasala commented May 12, 2021

It's on the roadmap - there are also quite a few inconsistencies with the storybook plugin too

@smasala
Copy link
Contributor

smasala commented Jun 8, 2021

Version 12.3.6 of @nrwl/web:

/node_modules/webpack/lib/Dependency.js:311
                throw new Error(
                ^

Error: module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)
at ProvidedDependency.set (/node_modules/webpack/lib/Dependency.js:311:9)
    at iterationDependencies (/node_modules/@nrwl/web/node_modules/webpack/lib/Compilation.js:940:21)

@smasala
Copy link
Contributor

smasala commented Jun 8, 2021

@FrozenPandaz qq why is there a react label on this?

@Bulletninja
Copy link

If i try to upgrade to webpack 5 i get this:

Cannot read property 'tap' of undefined
TypeError: Cannot read property 'tap' of undefined
    at /..../node_modules/@pmmmwh/react-refresh-webpack-plugin/lib/index.js:236:65

which is this line:

compilation.hooks.additionalTreeRuntimeRequirements.tap(

which is referred to here:

pmmmwh/react-refresh-webpack-plugin#308 (comment)

@ValentinFunk
Copy link

Any news on this? With webpack5 now being the default for angular apps I just ran into this issue upgrading the workspace

@gabrielgagne
Copy link

Version 12.3.6 of @nrwl/web:

/node_modules/webpack/lib/Dependency.js:311
                throw new Error(
                ^

Error: module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)
at ProvidedDependency.set (/node_modules/webpack/lib/Dependency.js:311:9)
    at iterationDependencies (/node_modules/@nrwl/web/node_modules/webpack/lib/Compilation.js:940:21)

Same problem here, fresh app created with 'nx generate @nrwl/web:app myapp'

nwrl/web 12.5.8

@camasuri
Copy link

camasuri commented Jul 16, 2021

Hi everyone,

I have the same issue, any update that can help us?

@JustusNBB
Copy link

Somehow managed to break my setup with this too (I am on NX 11), seems NX 12 allows to manually enable Webpack5
npx nx g @nrwl/web:webpack5

https://nx.dev/latest/react/guides/webpack-5

@ainulhassanml
Copy link

@JustusNBB after running npx nx g @nrwl/web:webpack5 facing following error

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[3].oneOf[0].issuer has an unknown property 'test'. These properties are valid:
   object { and?, not?, or? }
   -> Logic operators used in a condition matcher.

any workaround to this issue?

@keshav-kishor
Copy link

keshav-kishor commented Mar 11, 2022

after upgrading to NX 13 still getting a similar issue:
Error: Unable to resolve @nrwl/web:build. Cannot find executor 'build' in \node_modules\@nrwl\web\executors.json.

any workaround for this?

@ValentinFunk
Copy link

I think the builder is called @nrwl/web:webpack now @keshav-kishor

@keshav-kishor
Copy link

I think the builder is called @nrwl/web:webpack now @keshav-kishor

Thanks, @kamshak it worked

@peter-coastpay-com
Copy link

is this issue still open? I am seeing an error like this

@stuart-clark-45
Copy link

I have the same issue with a react application :/

@hveiras
Copy link

hveiras commented Oct 3, 2022

Tested in 14.x

Executors have been renamed

"executor": "@nrwl/node:execute" -> "executor": "@nrwl/node:node"
"executor": "@nrwl/node:build" -> "executor": "@nrwl/node:webpack"

also applies for web:build -> web:webpack

see AliYusuf95 reply here: #9168

@PapaStef
Copy link

PapaStef commented Dec 20, 2022

This is still not working for me using @nrwl/web:dev-server when mapping env vars. I'm using 15.0.12 + Webpack 5:

new webpack.EnvironmentPlugin(ENV_VAR_ALLOW_LIST)

I'm getting the following error:

ERROR in Cannot read properties of undefined (reading 'tap')

@jaysoo
Copy link
Member

jaysoo commented Feb 27, 2023

This has been fixed a while back. If you are still using @nrwl/web make sure they are pointing to @nrwl/webpack. There is a migration to rename this for you, but if you manually upgraded packages you may have missed it.

We only support Webpack 5 now, not Webpack 4.

@jaysoo jaysoo closed this as completed Feb 27, 2023
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx type: bug
Projects
None yet
Development

No branches or pull requests