angular-architects / module-federation-plugin

MIT License
729 stars 198 forks source link

After build: "Cannot find module '@angular/build/src/builders/application'" #610

Closed yunusyerli1 closed 3 months ago

yunusyerli1 commented 3 months ago

After build, ı get following error: root@89b67c6e1813:/var/www/my-app# yarn run build:shell yarn run v1.22.22 $ ng run shell:build:production An unhandled exception occurred: Cannot find module '@angular/build/src/builders/application' Require stack:

My angular.json is:

{
  "$schema": "node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "core/app",
  "projects": {
    "shell": {
      "root": "core/app/shell",
      "sourceRoot": "core/app/shell/src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-architects/native-federation:build",
          "options": {
            "target": "shell:esbuild:production",
            "polyfills": []
          },
        "esbuild": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "outputPath": "public/dist/",
            "index": "core/app/shell/src/index.html",
            "polyfills": [
              "zone.js",
              "es-module-shims",
              "@angular/localize/init"
            ],
            "tsConfig": "core/app/shell/tsconfig.app.json",
            "assets": [
              {
                "glob": "**/*",
                "input": "core/app/shell/src/themes",
                "ignore": [
                  "**/*.scss"
                ],
                "output": "/themes/"
              },
              {
                "glob": "**/*",
                "input": "node_modules/tinymce",
                "output": "/tinymce/"
              }
            ],
            "styles": [
              "node_modules/bootstrap-css-only/css/bootstrap.min.css",
              "core/app/shell/src/themes/myapp/css/style.scss",
              "node_modules/primeng/resources/themes/bootstrap4-light-blue/theme.css",
              "node_modules/primeng/resources/primeng.min.css"
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "core/app/shell/src/themes/*/css"
              ]
            },
            "deployUrl": "dist/browser/",
            "scripts": [
              "node_modules/tinymce/tinymce.min.js"
            ],
            "allowedCommonJsDependencies": [
              "graphql-tag",
              "zen-observable",
              "seedrandom",
              "@angular-architects/native-federation",
              "rfdc",
              "typed-function",
              "complex.js",
              "javascript-natural-sort",
              "tiny-emitter",
              "escape-latex"

            ],
            "browser": "core/app/shell/src/main.ts"
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "core/app/shell/src/environments/environment.ts",
                  "with": "core/app/shell/src/environments/environment.prod.ts"
                }
              ],
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractLicenses": true
            },
            "development": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true,
              "deployUrl": "dist/browser/",
              "budgets": [
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ]
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-architects/native-federation:build",
          "options": {
            "target": "shell:serve-original:development",
            "rebuildDelay": 0,
            "dev": true
          }
        },
        "serve-original": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "buildTarget": "shell:esbuild:production"
            },
            "development": {
              "buildTarget": "shell:esbuild:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "shell:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "tsConfig": "core/app/shell/tsconfig.spec.json",
            "assets": [
              "core/app/shell/src/themes"
            ],
            "styles": [
              "node_modules/bootstrap-css-only/css/bootstrap.min.css",
              "core/app/shell/src/themes/myapp/css/style.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-eslint/builder:lint",
          "options": {
            "eslintConfig": "./.eslintrc.js",
            "tsConfig": "core/app/shell/tsconfig.app.json",
            "fix": true
          }
        }
      }
    },
    "core": {
      "projectType": "library",
      "root": "core/app/core",
      "sourceRoot": "core/app/core/src",
      "prefix": "lib",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:ng-packagr",
          "options": {
            "tsConfig": "core/app/core/tsconfig.lib.json",
            "project": "core/app/core/ng-package.json"
          },
          "configurations": {
            "production": {
              "tsConfig": "core/app/core/tsconfig.lib.prod.json"
            },
            "development": {
              "tsConfig": "core/app/core/tsconfig.lib.json"
            }
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "core/app/core/src/test.ts",
            "tsConfig": "core/app/core/tsconfig.spec.json",
            "karmaConfig": "core/app/core/karma.conf.js",
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "styles": [
              "node_modules/bootstrap-css-only/css/bootstrap.min.css"
            ],
            "scripts": [],
            "assets": []
          }
        }
      }
    },
    "defaultExt": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "extensions/defaultExt",
      "sourceRoot": "extensions/defaultExt/app/src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-architects/native-federation:build",
          "options": {
            "target": "defaultExt:esbuild:production",
            "polyfills": []
          }
        },
        "esbuild": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "outputPath": "extensions/defaultExt/public",
            "index": "extensions/defaultExt/app/src/index.html",
            "polyfills": [
              "zone.js",
              "es-module-shims"
            ],
            "tsConfig": "extensions/defaultExt/app/tsconfig.app.json",
            "assets": [
              "extensions/defaultExt/app/src/favicon.ico",
              "extensions/defaultExt/app/src/assets"
            ],
            "styles": [
              "extensions/defaultExt/app/src/styles.scss"
            ],
            "scripts": [],
            "browser": "extensions/defaultExt/app/src/main.ts"
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "extensions/defaultExt/app/src/environments/environment.ts",
                  "with": "extensions/defaultExt/app/src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractLicenses": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ]
            },
            "development": {
              "outputPath": "public/extensions/defaultExt",
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-architects/native-federation:build",
          "options": {
            "target": "defaultExt:serve-original:development",
            "rebuildDelay": 0,
            "dev": true
          }
        },
        "serve-original": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "buildTarget": "defaultExt:esbuild:production"
            },
            "development": {
              "buildTarget": "defaultExt:esbuild:development",
              "port": 4201
            }
          },
          "defaultConfiguration": "development"
        },

        }
      }
    },
  },
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "style": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  },
  "cli": {
    "packageManager": "yarn",
    "analytics": false
  }
}

Package.json is:

{
  "name": "my-app",
  "version": "8.6.1",
  "scripts": {
    "ng": "ng",
    "start": "npm run start:shell",
    "start:shell": "ng serve shell  -o --port 5000",
    "start:all": "concurrently \"npm run start:shell\"",
    "serve:dist": "concurrently \"serve dist/shell -l 5000 -s\"",
    "build-dev": "npm run build-dev:core && npm run build-dev:shell ",
    "build-dev:shell": "ng run shell:build:development",
    "build-dev:core": "ng build core",
    "build-dev:defaultExt": "ng build defaultExt --configuration dev",
    "build": "npm run build:shell",
    "build:shell": "ng run shell:build:production",
    "build:core": "ng build core --configuration production",
    "build:defaultExt": "ng run defaultExt:esbuild:production",
    "test": "npm run test:shell",
    "test:core": "ng test core",
    "gen-index": "barrelsby --delete -e '.*\\.spec.*' -q",
    "gen-index:core": "barrelsby --delete -e '.*\\.spec.*' -q -d core/app/core/src/lib/ -n core",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "engines": {
    "node": ">= 10.0.0"
  },
  "browserslist": [
    "defaults"
  ],
  "dependencies": {
    "@angular-architects/native-federation": "^18.0.2",
    "@angular/animations": "18.1.2",
    "@angular/cdk": "^18.1.2",
    "@angular/common": "18.1.2",
    "@angular/compiler": "18.1.2",
    "@angular/core": "18.1.2",
    "@angular/forms": "18.1.2",
    "@angular/localize": "18.1.2",
    "@angular/platform-browser": "18.1.2",
    "@angular/platform-browser-dynamic": "18.1.2",
    "@angular/router": "18.1.2",
    "@apollo/client": "^3.11.1",
    "@ng-bootstrap/ng-bootstrap": "17.0.0",
    "@nrwl/workspace": "^19.5.3",
    "@popperjs/core": "^2.11.8",
    "@swimlane/ngx-charts": "^20.5.0",
    "@tinymce/tinymce-angular": "^8.0.1",
    "@types/object-hash": "^3.0.6",
    "ajv": "~8.17.1",
    "angular-svg-icon": "^18.0.1",
    "apollo-angular": "^7.0.2",
    "bootstrap": "^5.3.3",
    "bootstrap-css-only": "^4.4.1",
    "concurrently": "^8.2.2",
    "core-js": "^3.37.1",
    "es-module-shims": "^1.10.0",
    "graphql": "^16.9.0",
    "lodash-es": "^4.17.21",
    "luxon": "3.4.4",
    "mathjs": "^13.0.3",
    "ng-animate": "^2.0.1",
    "ng-dynamic-component": "^10.7.0",
    "ngx-chips": "^3.0.0",
    "nyc": "~17.0.0",
    "object-hash": "^3.0.0",
    "primeng": "^17.18.5",
    "rxjs": "^7.8.1",
    "tinymce": "^7.2.1",
    "tslib": "^2.6.3",
    "zone.js": "~0.14.8"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^18.1.2",
    "@angular-eslint/builder": "18.1.0",
    "@angular/cli": "18.1.2",
    "@angular/compiler-cli": "18.1.2",
    "@angular/language-service": "18.1.2",
    "@eslint/config-array": "^0.17.1",
    "@eslint/object-schema": "^2.1.4",
    "@types/jasmine": "~5.1.4",
    "@types/jasminewd2": "^2.0.13",
    "@types/lodash-es": "^4.17.12",
    "@types/luxon": "3.4.2",
    "@types/node": "^20.14.12",
    "@typescript-eslint/eslint-plugin": "^7.17.0",
    "@typescript-eslint/parser": "^7.17.0",
    "barrelsby": "^2.8.1",
    "eslint": "^8.56.0",
    "eslint-import-resolver-alias": "^1.1.2",
    "eslint-import-resolver-typescript": "^3.6.1",
    "eslint-plugin-compat": "^6.0.0",
    "eslint-plugin-import": "^2.29.1",
    "eslint-plugin-jasmine": "^4.2.0",
    "eslint-plugin-jsdoc": "^48.8.3",
    "eslint-plugin-prefer-arrow": "^1.2.3",
    "jasmine-core": "~5.2.0",
    "jasmine-spec-reporter": "~7.0.0",
    "karma": "~6.4.3",
    "karma-chrome-launcher": "~3.2.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-firefox-launcher": "^2.1.3",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "^2.1.0",
    "ng-packagr": "^18.1.0",
    "prettier": "^3.3.3",
    "ts-node": "^10.9.2",
    "typescript": "~5.5.4"
  }
}
amipei commented 3 months ago

If you use pnpm, you can set public-hoist-pattern=@angular/build in .npmrc file. public-hoist-pattern=*@angular/build*

My guess is that pnpm and npm handle dependencies differently (yarn should be similar)