ngcc fails and produces a confusing error when a library points to a non-existent file

Describe the bug

Angular language service crashing on startup due to ngcc failure. I believe this has been happening for a few versions, but haven’t had time to report till now.

Error: Error on worker angular/vscode-ng-language-service#6: Error: Invariant violated: No format-path or format for /Users/lincoln/Desktop/example/node_modules/@rx-angular/template : main (formatPath: bundles/rx-angular-template.umd.js | format: undefined)

To Reproduce

Steps to reproduce the behavior:

  1. ng new (example, css)
  2. cd example
  3. npm i @rx-angular/template
  4. Add rx-angular PushModule to app.module.ts
  5. Restart vscode
  6. boom

Expected behavior

Language server should not crash.

Logs

Please attach two logs:

  1. Console output (Go to toolbar –> View –> Output, and copy the contents)
[Info  - 12:33:09 AM] Angular language server process ID: 97613
[Info  - 12:33:09 AM] Using typescript/lib/tsserverlibrary v4.1.5 from /Users/lincoln/.vscode/extensions/angular.ng-template-11.2.3/node_modules/typescript/lib/tsserverlibrary.js
[Info  - 12:33:09 AM] Using @angular/language-service/bundles/ivy v11.2.2 from /Users/lincoln/.vscode/extensions/angular.ng-template-11.2.3/node_modules/@angular/language-service/bundles/ivy.js
[Info  - 12:33:09 AM] Log file: /Users/lincoln/Library/Application Support/Code/logs/20210219T103132/exthost6/Angular.ng-template/nglangsvc.log
[Info  - 12:33:09 AM] Disabling language service for /Users/lincoln/Desktop/example/tsconfig.json because it is not an Angular project ('@angular/core/core.d.ts' could not be found). If you believe you are seeing this message in error, please reinstall the packages in your package.json.
[Error - 12:33:16 AM] Failed to run ngcc for /Users/lincoln/Desktop/example/tsconfig.app.json:
    ngcc for /Users/lincoln/Desktop/example/tsconfig.app.json returned exit code 1, stderr: �[33mWarning:�[0m Entry point '@rx-angular/template/schematics' contains deep imports into '/Users/lincoln/Desktop/example/node_modules/@schematics/angular/utility/ast-utils', '/Users/lincoln/Desktop/example/node_modules/@schematics/angular/utility/dependencies'. This is probably not a problem, but may cause the compilation of entry points to be out of order.
Error: Error on worker angular/vscode-ng-language-service#6: Error: Invariant violated: No format-path or format for /Users/lincoln/Desktop/example/node_modules/@rx-angular/template : main (formatPath: bundles/rx-angular-template.umd.js | format: undefined)
    at /Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/create_compile_function.js:44:27
    at /Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/worker.js:85:54
    at step (/Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:143:27)
    at Object.next (/Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:124:57)
    at /Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:113:16)
    at Worker.<anonymous> (/Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/worker.js:72:78)
    at Worker.emit (events.js:315:20)
    at process.<anonymous> (internal/cluster/worker.js:32:12)
    at ClusterMaster.onWorkerMessage (/Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:195:27)
    at /Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:55:95
    at ClusterMaster.<anonymous> (/Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:293:57)
    at step (/Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:143:27)
    at Object.next (/Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:124:57)
    at /Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/lincoln/Desktop/example/node_modules/tslib/tslib.js:113:16)
    at EventEmitter.<anonymous> (/Users/lincoln/Desktop/example/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:287:32)
    at EventEmitter.emit (events.js:315:20)
    Language service will remain disabled.
[Info  - 12:33:16 AM] Enabling Ivy language service for /Users/lincoln/Desktop/example/tsconfig.app.json.

  1. Log file (Path is printed to the console output at startup)

nglangsvc.log

Screenshots

If applicable, add screenshots to help explain your problem.

Example Screenshot
image

Additional context

Add any other context about the problem here.

1 possible answer(s) on “ngcc fails and produces a confusing error when a library points to a non-existent file

  1. To give some more context:

    While this is indeed an issue with @rx-angular/template, ngcc should be able to handle it more gracefully (in general – i.e. independent of the Language Service). With #40985, ngcc will print a more descriptive error and continue working on the rest of its tasks.

    Regarding the failure with Language Service specifically:
    Currently, the Language Service (LS) will try to process all available formats of each entry-point. This wasteful, since the LS only cares about the typings (for which any one format would suffice). So, in this particular case, the LS doesn’t really need ngcc to try to process the main property of @rx-angular/template at all, since processing fesm2015 would be enough.

    #40976 will provide a way for the LS to only process one entry point for each package (and only for the purpose of generating updated typings), which will also help avoid issues such as this one.