question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't run api-extractor on library compiled with ivy

See original GitHub issue

Bug Report

Affected Package

The issue is caused by package @angular/compiler-cli

Is this a regression?

No, though I should note this is only an issue with Ivy and not with ViewEngine.

Description

The .d.ts file generated by a partial ivy compilation is not compatible with @microsoft/api-extractor, a tool preferred by the APF document

As of APF v8 we now prefer to run the .d.ts bundler tool from https://api-extractor.com/ so that the entire API appears in a single file.

In prior APF versions each entry point would have a src directory next to the .d.ts entry point and this directory contained individual d.ts files matching the structure of the original source code. While this distribution format is still allowed and supported, it is highly discouraged because it confuses tools like IDEs that then offer incorrect autocompletion, and allows users to depend on deep-import paths which are typically not considered to be public API of a library or a package.

~ https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview#heading=h.d5w3fovwzg9

While this isn’t a bug in an angular package per se, the advise given in the APF document has pushed me towards opening this ticket as bug on the angular/angular repo and not as feature in microsoft/rushstack.

Minimal Reproduction

cd $(mktemp -d)
git clone github.com/bgotink/angular-repro-42063 .
yarn
yarn build

Disable enableIvy in the tsconfig.json file and yarn build will work.

Exception or Error

Error while running api-extractor:

ERROR: "import * as ___ from ___;" is not supported yet for local files.
/private/var/folders/_d/ch2kc4h960d10cy_2c41qqzw0000gn/T/tmp.6Rkk9EFSAa/dist/module.d.ts:3:1

The dist/module.d.ts file the error points to:

import { MyDirective } from './directive';
import * as i0 from "@angular/core";
import * as i1 from "./directive";
export declare class MyModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<MyModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<MyModule, [typeof i1.MyDirective], never, [typeof i1.MyDirective]>;
    static ɵinj: i0.ɵɵInjectorDeclaration<MyModule>;
}
export { MyDirective };

Your Environment

Angular Version:

@angular/* version 12.0.0-rc.3, ng-packagr version 12.0.0-rc.3, @microsoft/api-extractor version 7.15.1

Anything else relevant?

We don’t actually use ng-packagr. Our (private) toolchain yields the exact same output so I used ng-pacakgr for the reproduction. We follow the APF document’s preference and run @microsoft/api-extractor to roll up the .d.ts files.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Jul 2, 2021

@bgotink Heya, api-extractor 7.17.0 has added support for namespace import bundling. It does however depend on a change to the Angular compiler that is part of #42728 to support the flattened output for these namespace imports, that will be part of next minor release. Consequently, libraries that have been flattened using api-extractor would require an Angular version that is at minimum 12.2 (the next minor), so that may be something to keep in mind.

0reactions
angular-automatic-lock-bot[bot]commented, Aug 8, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why shouldn't I publish libraries compiled with Ivy?
As stated in this answer on that github link. The reason is actually forward compatibility. If we allow ivy compiled libraries to be ......
Read more >
What's new in Angular 9? - ParTech
The new Ivy compiler will be the default, so Angular apps built with Ivy will be ... Possibly, you won't notice the change...
Read more >
Understanding Angular Ivy Library Compilation | lacolaco/tech
In this post, I will explain how to compile Angular libraries with Ivy, which is now possible in Angular v11.1, and its details....
Read more >
Angular Package Format - W3cubDocs
It is recommended that third-party library developers follow the same npm ... does not use the Angular CLI then refer to the Consuming...
Read more >
What's new with Angular 9? - AnAr Solutions Pvt. Ltd.
Angular 9 is an open source framework developed by Google, built using HTML ... With new release Ivy is now a default compiler...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found