Repository navigation
Description
🐞 bug report
Affected Package
The issue is caused by ivy-ngcc toolIs this a regression?
no
Description
ivy-ngcc transforms UMD bundles incorrectly. In particular, the symbol Injectable ends up as undefined in the transformed UMD bundle.
AriaDescriber.decorators = [
{ type: core.Injectable, args: [{ providedIn: 'root' },] },
];
/** @nocollapse */
AriaDescriber.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] }
]; };
/** @nocollapse */ AriaDescriber.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function AriaDescriber_Factory() { return new AriaDescriber(core.ɵɵinject(common.DOCUMENT)); }, token: AriaDescriber, providedIn: "root" });
return AriaDescriber;
in node_modules/@angular/cdk/bundles/cdk-a11y.umd.js.__ivy_ngcc_bak gets transformed to
/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(AriaDescriber, [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], function () { return [{ type: undefined, decorators: [{
type: Inject,
args: [common.DOCUMENT]
}] }]; }, { _document: [], describe: [], removeDescription: [], ngOnDestroy: [], _createMessageElement: [], _deleteMessageElement: [], _createMessagesContainer: [], _deleteMessagesContainer: [], _removeCdkDescribedByReferenceIds: [], _addMessageReference: [], _removeMessageReference: [], _isElementDescribedByMessage: [], _canBeDescribed: [], _isElementNode: [] });
return AriaDescriber;
in node_modules/@angular/cdk/bundles/cdk-a11y.umd.js where type: Injectable, is undefined when run in the browser:
Uncaught ReferenceError: Injectable is not defined
I would guess it should be type: core.Injectable since core is the @angular/core UMD dependency.
@angular/cdk/bundles/cdk-a11y.umd.js is just an example but same thing happens in other bundles transformed.
🔬 Reproduction
Clone the wassim/ivy branch of my fork of angular-bazel-example (https://github.com/gregmagolan/angular-bazel-example/tree/wassim/ivy) and run yarn install. ivy-ngcc is run in the postinstall step and you can inspect the resulting transofmed bundles under node_modules.
🔥 Exception or Error
🌍 Your Environment
Angular Version:
Anything else relevant?
Activity
alexzuza commentedon Jul 3, 2019
The same also happens with
@angular/*umd bundles.I think the problem is located here
angular/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts
Lines 124 to 127 in 21835af
If I check for property access then it works for me:
@alxhub Can you please take a look at this?
petebacondarwin commentedon Jul 3, 2019
I'll take a look.
fix(ivy): ngcc - render namespaced imported decorators correctly
petebacondarwin commentedon Jul 5, 2019
Hopefully #31426 should fix this.
fix(ivy): ngcc - render namespaced imported decorators correctly (#31426
gregmagolan commentedon Jul 19, 2019
@petebacondarwin Thanks for the fix. I have good news and bad news. Will start with the good 🚀
Good) Your fix (landed in master & 8.1.x branch) fixed the issue observed for all of the angular bundles. The ivy-ngcc generated file
node_modules/@angular/cdk/bundles/cdk-a11y.umd.jsfile now has:which correctly has
type: core.Injectable,Bad) The @ngrx umd bundles (from latest 8.1.0 release) still have the same error originally observed in the angular bundles
in
node_modules/@ngrx/store/bundles/store.umd.js.__ivy_ngcc_bakis transformed toin
node_modules/@ngrx/store/bundles/store.umd.jswhich hastype: Injectableagain and it fails in the browser at runtime.There is a slight difference in that the ngrx bundle, which has
core.Injectable(),while the issue observed with the cdk bundlenode_modules/@angular/cdk/bundles/cdk-a11y.umd.js.__ivy_ngcc_bakhadtype: core.Injectable,.petebacondarwin commentedon Jul 19, 2019
I think the difference is that one uses the static property style of decoration and the other uses the call helper style.
vs
I guess we only fixed it for the static property style.
JoostK commentedon Jul 27, 2019
I can confirm this was only fixed for the static properties syntax, not the
__decoratesyntax. I included a fix in #31614 which contains some more fixes to deal with decorators correctly.fix(ivy): ngcc - render decorators in UMD and CommonJS bundles correctly
gregmagolan commentedon Aug 15, 2019
Confirmed that all the UMD bundles used by angular-bazel-example (including @ngrx which was using
core.Injectable()) are correctly transformed now with ivy-ngcc from angular 9.0.0-next.2. Tested in angular/angular-bazel-example#505. Thanks @petebacondarwin @JoostK!@alexeagle @CaerusKaru ^^
fix(ivy): ngcc - render namespaced imported decorators correctly (ang…
fix(ivy): ngcc - render decorators in UMD and CommonJS bundles correc…
angular-automatic-lock-bot commentedon Sep 15, 2019
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.