angular / angular

Deliver web apps with confidence πŸš€
https://angular.dev
MIT License
95.88k stars 25.32k forks source link

Library distribution with compilationMode: partial error #40514

Closed vthinkxie closed 3 years ago

vthinkxie commented 3 years ago

🐞 bug report

Affected Package

unknow

Is this a regression?

no

Description

throw below error when building ivy lib with the configuration

An unhandled exception occurred: error NG4001: Angular compiler option "flatModuleOutFile" requires one and only one .ts file in the "files" field.

{
  "extends": "./tsconfig.lib.json",
  "compilerOptions": {
    "declarationMap": false
  },
  "angularCompilerOptions": {
    "enableIvy": true,
    "compilationMode": "partial"
  }
}

https://github.com/mgechev/ivy-library-distribution-demo

πŸ”¬ Minimal Reproduction

Pull Request: https://github.com/NG-ZORRO/ng-zorro-antd/pull/6362

Exception: https://dev.azure.com/ng-zorro/NG-ZORRO/_build/results?buildId=3206&view=logs&j=8680be89-378c-5901-27b8-79bf589da266&t=7cc10bac-49f7-5748-d4ee-64732cd3a79d

πŸ”₯ Exception or Error


An unhandled exception occurred: error NG4001: Angular compiler option "flatModuleOutFile" requires one and only one .ts file in the "files" field.

🌍 Your Environment

Angular Version:


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 11.1.0
Node: 12.13.1
OS: darwin x64

Angular: 11.1.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1101.0
@angular-devkit/build-angular   0.1101.0
@angular-devkit/core            11.1.0
@angular-devkit/schematics      11.1.0
@nguniversal/builders           11.1.0
@nguniversal/express-engine     11.1.0
@schematics/angular             11.1.0
@schematics/update              0.1101.0
ng-packagr                      11.1.2
rxjs                            6.6.3
typescript                      4.0.5

Anything else relevant?

petebacondarwin commented 3 years ago

I have debugged this build and it appears that the problem is actually that the entryFile path in ng-package.json is incorrect. It should have an extension (i.e. "./public_api.ts"). See https://github.com/NG-ZORRO/ng-zorro-antd/blob/df03ffb7f045271056e03e4659f7e845003c3bde/components/ng-package.json#L6

Unfortunately the error is not picked up until much later when the compiler tries to load the entry-point and thinks that there is none there - ngtsc (the ivy compiler) filters out input files that do not end with .ts. See https://github.com/angular/angular/blob/7c161e167907cea92f25df192e0dde789e0cfd43/packages/compiler-cli/src/ngtsc/core/src/host.ts#L172-L178

So on the ng-zorro-antd side the fix is to change the path in that file. (Also it might be worth removing this includes as well: https://github.com/NG-ZORRO/ng-zorro-antd/blob/df03ffb7f045271056e03e4659f7e845003c3bde/components/tsconfig.lib.json#L26)

On our side we need to:

  1. Work out if we could provide a better error message in ng-packagr <-- cc @alan-agius4
  2. Work out if we actually need to care about the flatModuleOutFile option in Ivy builds, since I understand that it was only designed to generate a flat metadata.json file, which is not needed for Ivy builds. <-- cc @alxhub and @JoostK
vthinkxie commented 3 years ago

Hi

Everything works fine with angular 11.1.1, thanks a lot

petebacondarwin commented 3 years ago

Thanks for the update. I see in your referenced PR that you are removing the files property from tsconfig.json. I think that is what solves the problem rather than any change in 11.1.1.

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.