angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.77k stars 11.97k forks source link

ng build --prod=true fails with global scripts in agular.json when opt-in to Webpack 5 #19598

Closed nchangnon closed 3 years ago

nchangnon commented 3 years ago

🐞 Bug report

Command (mark with an x)

Is this a regression?

This works when not opting-in to Webpack 5.

Description

A clear and concise description of the problem... -->

If scripts are specified in the build options to be included globally, ng build --prod=true fails to build.

πŸ”¬ Minimal Reproduction

  1. create a new angular project

  2. opt-in to webpack 5 : "resolutions": { "webpack": "5.4.0" }

  3. add an external dependency such as jquery to package.json (using yarn) yarn add jquery

  4. update angular.json to include the new global dependency


  "projects": {
    "wp5": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/wp5",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": [
              "./node_modules/jquery/dist/jquery.min.js"
            ]
          }
     ...
   }

  1. run ng build --prod=true

πŸ”₯ Exception or Error




wp5 % ng build --prod=true
βœ” Browser application bundle generation complete.
An unhandled exception occurred: Chunk.modulesIterableThere was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)
See "/private/var/folders/km/qmp0wv016q9chrhmsr34qdp80000gn/T/ng-zRypdH/angular-errors.log" for further details.

🌍 Your Environment




Angular CLI: 11.0.4
Node: 15.3.0
OS: darwin x64

Angular: 11.0.3
... animations, common, compiler, core, forms, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1101.0-next.2
@angular-devkit/build-angular   0.1101.0-next.2
@angular-devkit/core            11.0.4
@angular-devkit/schematics      11.0.4
@angular/cli                    11.0.4
@angular/compiler-cli           11.0.4
@schematics/angular             11.0.4
@schematics/update              0.1100.4
rxjs                            6.6.3
typescript                      4.0.5

Anything else relevant?

alan-agius4 commented 3 years ago

Duplicate of https://github.com/angular/angular-cli/issues/19550

Addressed in ~0.1101.0-next.2, to try out the prerelease run ng update @angular/cli --next

nchangnon commented 3 years ago

@alan-agius4 This bug is present in 0.1101.0-next.2 , see the 'Your Environment' section. This is different than #19550 which did build successful but just had issues with running locally. I can now run locally (ng serve) but can no longer do a production build (ng build --prod==true)

alan-agius4 commented 3 years ago

I actually managed to replicate it. For some reason I wasn't before when I used the latest version of Webpack. It appears to be caused by the license-webpack-plugin plugin. Disabling license extraction doesn't cause an error.

ng build --prod --no-extract-licenses
alan-agius4 commented 3 years ago

Closing as it's currently fixed on master branch and will be part of the 11.1 release.

angular-automatic-lock-bot[bot] commented 3 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.