angular-architects / module-federation-plugin

MIT License
730 stars 199 forks source link

Build not working after v18 upgrade: ERR_PACKAGE_PATH_NOT_EXPORTED './src/builders/application' in @angular/build/package.json #609

Closed vdumitrache closed 3 months ago

vdumitrache commented 3 months ago

Upgrading to the latest Angular + Native federation (18.0.2).

The error happens within an multi-project Angular Workspace, when I try to build the MFE.

Console error: _An unhandled exception occurred: Package subpath './src/builders/application' is not defined by "exports" in D:\Projects\\nodemodules\@angular\build\package.json

Full error:

[error] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './src/builders/application' is not defined by "exports" in D:\Projects\<project-name>\node_modules\@angular\build\package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:651:9)
    at resolveExports (node:internal/modules/cjs/loader:590:36)
    at Module._findPath (node:internal/modules/cjs/loader:667:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1129:27)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (D:\Projects\<project-name>\node_modules\@angular-architects\native-federation\src\builders\build\builder.js:9:23)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)

Full package.json:

 "dependencies": {
    "@angular/animations": "^18.1.2",
    "@angular/cdk": "~18.1.0",
    "@angular/common": "^18.1.2",
    "@angular/compiler": "^18.1.2",
    "@angular/core": "^18.1.2",
    "@angular/forms": "^18.1.2",
    "@angular/material": "^18.1.0",
    "@angular/platform-browser": "^18.1.2",
    "@angular/platform-browser-dynamic": "^18.1.2",
    "@angular/router": "^18.1.2",
    "@messageformat/core": "^3.3.0",
    "@ngx-translate/core": "^15.0.0",
    "@ngx-translate/http-loader": "^8.0.0",
    "es-module-shims": "^1.5.12",
    "ngx-translate-messageformat-compiler": "^7.0.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.3"
  },
  "devDependencies": {
    "@angular-architects/native-federation": "^18.0.2",
    "@angular-builders/jest": "^18.0.0",
    "@angular-devkit/build-angular": "^18.1.2",
    "@angular-eslint/builder": "18.1.0",
    "@angular-eslint/eslint-plugin": "18.1.0",
    "@angular-eslint/eslint-plugin-template": "18.1.0",
    "@angular-eslint/schematics": "18.1.0",
    "@angular-eslint/template-parser": "18.1.0",
    "@angular/cli": "^18.1.2",
    "@angular/compiler-cli": "^18.1.2",
    "@commitlint/cli": "^19.3.0",
    "@commitlint/config-conventional": "^19.2.2",
    "@compodoc/compodoc": "^1.1.24",
    "@double-great/stylelint-a11y": "^3.0.2",
    "@storybook/addon-docs": "^8.1.1",
    "@storybook/addon-essentials": "^8.1.1",
    "@storybook/addon-interactions": "^8.1.1",
    "@storybook/addon-links": "^8.1.1",
    "@storybook/angular": "^8.1.1",
    "@storybook/blocks": "^8.1.1",
    "@storybook/test": "^8.1.1",
    "@types/jest": "^29.5.12",
    "@typescript-eslint/eslint-plugin": "7.17.0",
    "@typescript-eslint/parser": "7.17.0",
    "commitlint-plugin-regex-match": "^1.2.4",
    "eslint": "^8.57.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-import": "^2.29.1",
    "eslint-plugin-jest": "^28.3.0",
    "eslint-plugin-jest-formatting": "^3.1.0",
    "eslint-plugin-prefer-arrow": "^1.2.3",
    "eslint-plugin-prettier": "^5.1.3",
    "eslint-plugin-sort-exports": "^0.9.1",
    "eslint-plugin-storybook": "^0.8.0",
    "husky": "^9.0.11",
    "jest": "^29.7.0",
    "jest-preset-angular": "^14.0.4",
    "lint-staged": "^15.2.2",
    "ng-packagr": "^18.1.0",
    "ngx-translate-testing": "^7.0.0",
    "prettier": "^3.2.5",
    "storybook": "^8.1.1",
    "stylelint": "^16.4.0",
    "stylelint-config-recommended": "^14.0.0",
    "stylelint-config-standard": "^36.0.0",
    "stylelint-config-standard-scss": "^13.1.0",
    "stylelint-scss": "^6.3.0",
    "typescript": "~5.5.4"
  }

The angular.json builder is "@angular-architects/native-federation:build" calling an esbuild @angular-devkit/build-angular:application

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)

GregOnNet commented 3 months ago

Thanks @amipei,

your comment saved us a lot of time. For the record:

@amipei Do you know why we need this?

@manfredsteyer We should keep an I on this since this is not a good DX, imho.

GregOnNet commented 3 months ago

According to pnpm's docs, we maybe have a bug here: https://pnpm.io/npmrc#public-hoist-pattern

This setting is useful when dealing with some flawed pluggable tools that don't resolve dependencies properly.

manfredsteyer commented 3 months ago

Hi,

thanks for pointing this out. This is now resolved with version 18.1, which lands very soon.