Cannot find module angular-devkit/build-ng-packagr/package.json error

Viewed 843

I have Cannot find module '@angular-devkit/build-ng-packagr/package.json' error when I run node_modules\.bin\ng build --prod --build-optimizer=true or node_modules\.bin\ng build --prod --aot=true --build-optimizer=true commands.

**[error] Error: Cannot find module '@angular-devkit/build-ng-packagr/package.json' Require stack:

  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular-devkit\architect\node\node-modules-architect-host.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular-devkit\architect\node\index.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\models\architect-command.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\commands\build-impl.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular-devkit\schematics\tools\export-ref.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular-devkit\schematics\tools\index.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\utilities\json-schema.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\models\command-runner.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\lib\cli\index.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\lib\init.js
  • D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\bin\ng at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15) at Function.resolve (internal/modules/cjs/helpers.js:94:19) at WorkspaceNodeModulesArchitectHost.resolveBuilder (D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular-devkit\architect\node\node-modules-architect-host.js:85:41) at BuildCommand.initialize (D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\models\architect-command.js:76:63) at async BuildCommand.validateAndRun (D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\models\command.js:127:9) at async Object.runCommand (D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\models\command-runner.js:204:24) at async default_1 (D:\ktmvgit\Katimavik\Katimavik\WebUI\KatimavikUI\ClientApp\node_modules@angular\cli\lib\cli\index.js:80:31)**

When I run node_modules\.bin\ng build --prod distribution build is created successfully. But I need to optimize my production build so I am trying add --aot=true --build-optimizer=true flags

I have already tried remove node_modules and reinstall packages, reinstall @angular-devkit/build-angular with '--force' at the end but it didn't help.

Maybe someone will have any recommendation or indicate something wrong in my file configuration files. Here is my package.json file:

{
    "name": "katimavik",
    "version": "0.0.0",
    "scripts": {
        "ng": "ng",
        "start": "echo hello && ngserve",
        "build": "ng build --prod",
        "build:ssr": "ng run Katimavik:server:dev",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "ng-serve": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve --live-reload=false --open"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^11.2.3",
        "@angular/cdk": "^11.2.2",
        "@angular/common": "^11.2.3",
        "@angular/compiler": "^11.2.3",
        "@angular/core": "^11.2.3",
        "@angular/forms": "^11.2.3",
        "@angular/platform-browser": "^11.2.3",
        "@angular/platform-browser-dynamic": "^11.2.3",
        "@angular/router": "^11.2.3",
        "@angular/service-worker": "^11.2.3",
        "@aspnet/signalr": "^1.1.4",
        "@auth0/angular-jwt": "^5.0.2",
        "@material/tabs": "^2.3.0",
        "@ng-bootstrap/ng-bootstrap": "^9.0.2",
        "@ngx-translate/core": "^13.0.0",
        "@ngx-translate/http-loader": "^6.0.0",
        "@progress/kendo-angular-buttons": "^6.1.0",
        "@progress/kendo-angular-common": "^2.0.0",
        "@progress/kendo-angular-dateinputs": "^5.1.0",
        "@progress/kendo-angular-dialog": "^5.0.0",
        "@progress/kendo-angular-dropdowns": "^5.1.0",
        "@progress/kendo-angular-excel-export": "^4.0.0",
        "@progress/kendo-angular-grid": "^5.0.2",
        "@progress/kendo-angular-inputs": "^7.1.2",
        "@progress/kendo-angular-intl": "^3.1.0",
        "@progress/kendo-angular-l10n": "^3.0.0",
        "@progress/kendo-angular-label": "^3.0.0",
        "@progress/kendo-angular-notification": "^3.0.0",
        "@progress/kendo-angular-pdf-export": "^3.0.0",
        "@progress/kendo-angular-popup": "^4.0.0",
        "@progress/kendo-angular-treeview": "^5.0.0",
        "@progress/kendo-angular-upload": "^7.1.0",
        "@progress/kendo-data-query": "^1.5.4",
        "@progress/kendo-date-math": "^1.5.1",
        "@progress/kendo-drawing": "^1.9.4",
        "@progress/kendo-licensing": "^1.1.4",
        "@progress/kendo-theme-bootstrap": "^4.31.0",
        "@progress/kendo-ui": "^2021.1.225",
        "@progress/telerik-angular-report-viewer": "^12.21.224",
        "@telerik/kendo-intl": "^2.3.0",
        "@types/underscore": "^1.10.24",
        "bootstrap": "^4.6.0",
        "jquery": "^3.5.1",
        "lodash": "^4.17.21",
        "lodash-es": "^4.17.21",
        "ngx-filter-pipe": "^2.1.2",
        "ngx-order-pipe": "^2.1.1",
        "ngx-useful-swiper": "^9.0.5",
        "rxjs": "^6.6.6",
        "rxjs-compat": "^6.6.6",
        "signalr": "^2.4.1",
        "signalr-no-jquery": "^0.2.0",
        "swiper": "^5.4.5",
        "underscore": "^1.12.0",
        "zone.js": "^0.11.4"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "^0.1102.10",
        "@angular-devkit/build-optimizer": "^0.1102.10",
        "@angular/cli": "^11.2.2",
        "@angular/compiler-cli": "^11.2.3",
        "@angular/language-service": "^11.2.3",
        "@angular/localize": "^11.2.3",
        "@types/node": "^14.14.31",
        "@types/signalr-no-jquery": "^0.1.2",
        "ajv": "^7.1.1",
        "codelyzer": "^6.0.1",
        "cross-env": "^7.0.3",
        "fibers": "^5.0.0",
        "html-webpack-plugin": "^5.2.0",
        "ng-packagr": "^11.2.4",
        "npm": "7.6.0",
        "popper.js": "^1.16.1",
        "protractor": "^7.0.0",
        "rxjs-tslint": "^0.1.8",
        "ts-node": "^9.1.1",
        "tslib": "^2.1.0",
        "tslint": "^5.20.1",
        "typescript": "~4.0.3"
    }
}

Here is my angular.json file:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "Katimavik": {
      "root": "",
      "sourceRoot": "projects/src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/Katimavik",
            "index": "projects/src/index.html",
            "main": "projects/src/main.ts",
            "polyfills": "projects/src/polyfills.ts",
            "tsConfig": "projects/src/tsconfig.app.json",
            "assets": [
                "projects/src/assets",
                "projects/src/manifest.webmanifest",
                {
                    "glob": "*.{js,html}",
                    "input": "../../Katimavik",
                    "output": "/angularjs/"
                },
                {
                    "glob": "**/*",
                    "input": "../../Katimavik/assets",
                    "output": "/angularjs/assets/"
                },
                {
                    "glob": "**/*",
                    "input": "../../Katimavik/apps",
                    "output": "/angularjs/apps/"
                },
                {
                    "glob": "web.config",
                    "input": ".",
                    "output": "/"
                }
            ],
            "styles": [
              "projects/src/assets/css/kendo-theme-default/all.css",
              "assets/app-angular.css",
              "assets/main.css",
              "assets/index.css",
              "assets/angle/theme-f.css",
              "assets/fonts/fontawesome/css/font-awesome.min.css",
              "assets/fonts/simple-line-icons/css/simple-line-icons.css",
              "assets/fonts/katimavik/css/katimavik-font.css",
              "assets/angular/ngDialog/css/ngDialog.min.css",
              "assets/landing.css",
              "projects/src/assets/adeco/adeco-katimavik.min.css",
              "projects/src/assets/less/components/ng-number-picker.css",
              "projects/src/assets/less/components/angular-kendo-grid.css",
              "projects/src/assets/less/components/kendo-popup-dialog.css",
              "projects/src/assets/less/adecoColors.less",
              "projects/src/assets/less/adecoImageURL.css",
              "projects/src/assets/less/properties/margin.less",
              "projects/src/assets/less/properties/padding.less",
              "node_modules/swiper/css/swiper.css",
              "projects/src/styles.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/signalr/jquery.signalR.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "projects/src/environments/environment.ts",
                  "with": "projects/src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true,
              "ngswConfigPath": "ngsw-config.json"
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "Katimavik:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "Katimavik:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "Katimavik:build"
          }
        }
      }
    },
    "common": {
      "root": "projects/common",
      "sourceRoot": "projects/common/src",
      "projectType": "library",
      "prefix": "ktmv",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-ng-packagr:build",
          "options": {
            "tsConfig": "projects/common/tsconfig.lib.json",
            "project": "projects/common/ng-package.json"
          },
          "configurations": {
            "production": {
              "project": "projects/common/ng-package.prod.json"
            }
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "projects/common/src/test.ts",
            "tsConfig": "projects/common/tsconfig.spec.json",
            "karmaConfig": "projects/common/karma.conf.js"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "projects/common/tsconfig.lib.json",
              "projects/common/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "Katimavik",
  "cli": {
    "analytics": "92d1d885-883a-4330-b6ab-d87976797d0f"
  }
}

Here is my tsconfig.app.json file :

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

and my tsconfig.json file:

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "module": "es2015",
        "moduleResolution": "node",
        "allowSyntheticDefaultImports": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ],
        "plugins": [
            { "name": "@angular/language-service" }
        ],
        "paths": {
            "common": [
                "dist/common"
            ],
            "common/*": [
                "dist/common/*"
            ],
            "webapi": [
                "dist/webapi"
            ],
            "webapi/*": [
                "dist/webapi/*"
            ]
        }
    },
    "files": [
        "src/main.ts",
        "src/polyfills.ts",
        "src/app/devicemanagement/devicemanagement.module.ts",
        "src/app/landing/landing.module.ts",
        "src/app/login/login.module.ts",
        "src/app/programaudit/programaudit.module.ts",
        "src/app/reports/reports.module.ts",
        "src/app/settings/settings.module.ts",
        "src/app/usermanagement/usermanagement.module.ts"
    ]
}

Please let me know if I need to provide more informations or describe what I have already try to make node_modules\.bin\ng build --prod --aot=true --build-optimizer=true command work. Thanks in advance.

0 Answers
Related