Library distribution with compilationMode: partial error

🐞 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: NG-ZORRO/ng-zorro-antd#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?

1 possible answer(s) on “Library distribution with compilationMode: partial error

  1. 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

    const normalizedTsInputFiles: AbsoluteFsPath[] = [];
    for (const inputFile of inputFiles) {
    if (!isNonDeclarationTsPath(inputFile)) {
    continue;
    }
    normalizedTsInputFiles.push(resolve(inputFile));
    }

    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