-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
Which @angular/* package(s) are the source of the bug?
compiler-cli
Is this a regression?
No
Description
I ran into this issue when using ng-packager, which uses rollup internally, to package a library that I use in my main app. The format of the packaged UMD module changed with the new rollup version 2.57 and now Angular compiler is unable to sniff the module type as UMD, defaulting to CommonJS: https://github.com/angular/angular/blob/master/packages/compiler-cli/ngcc/src/packages/entry_point.ts#L279
Old, working format had the whole module wrapped in parenthesis, while the new one has the factory function and module body wrapped separately with no all-enclosing parenthesis.
The sniffing fails here:
angular/packages/compiler-cli/ngcc/src/host/umd_host.ts
Lines 532 to 534 in 9a6bd26
| if (!ts.isExpressionStatement(statement) || !ts.isParenthesizedExpression(statement.expression) || | |
| !ts.isCallExpression(statement.expression.expression) || | |
| !ts.isFunctionExpression(statement.expression.expression.expression)) { |
ts.isExpressionStatement -> true
ts.isParenthesizedExpression -> false
ts.isCallExpression -> false
ts.isFunctionExpression -> true
The UMD module is functionally the same, but ngcc makes assumptions about its structure and thus fails to correctly determine the module type. I asked about the change from rollup team and they said the change was intended.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
When compiling:
Compiling <my-library> : main as commonjs
In browser console:
> type <myModule> does not have 'ɵmod' property.
Please provide the environment you discovered this bug in
No response
Anything else?
No response