You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
compiler-cli: lowering_expression transformer does not handle forwardRef like function #20216
OK, for now, if by any change someone is interested, this is a working, monkey patching, workaround:
/** * This module will patch the `@angular/compiler-cli` so it will correctly lower expression to declarations in decorators. * See https://github.com/angular/angular/issues/20216 */import*astsfrom'typescript';import'@angular/compiler-cli';constlowerExpressions=require('@angular/compiler-cli/src/transformers/lower_expressions');functiontouchNode(node: ts.Node){if(!node.parent){constoriginal: ts.Node=<any>ts.getOriginalNode(node);if(original!==node&&original.parent){node.parent=original.parent;ts.forEachChild(node,touchNode)}}}constgetExpressionLoweringTransformFactory=lowerExpressions.getExpressionLoweringTransformFactory;lowerExpressions.getExpressionLoweringTransformFactory=function(requestsMap,program){constfn=getExpressionLoweringTransformFactory(requestsMap,program);returncontext=>sourceFile=>{constresult=fn(context)(sourceFile);if(result!==sourceFile){ts.forEachChild(result,touchNode)}returnresult;};};
just import this file in the top of your webpack config module, or if you use ngc invoke it from a local file.
Any tips on how to integrate this fix into an @angular/cli@1.5.0 project without having to ng eject?
Reacted by Philipp Denzler, Karim Saadi, Janne Julkunen, Phil Jones, ALDINEY MENDES SANTOS, dmostert, Matthew Salsamendi, Andrey Klimov and Kirill Groshkov
I want to share my workaround that I put together after reading other advices here and there. It's patching an ng script from @angular/cli@1.6.4 (current version at the moment of writing). Because of that it prevents updating @angular/cli, so be prepared.
Add a postinstall script in your package.json that will run every time after you do npm install (or yarn install) and copy/overwrite ng from your location to node_modules/@angular/cli/bin/ng.
@daixtrose My solution is when @angular/cli is used in the project. Seems you you don't use it (cause I can't see it in node_modules), then how do you compile your angular project? Anyway, if you dig deeper, you'll find what lines you need to add to your compiler script to make it work, good luck!
Apparently, this started working from Angular CLI 1.7 onwards, so somehow the CLI was involved. I can't reproduce this in newer versions of Angular (or even with Angular 5.0.0, TS 2.4.2 and CLI 1.7.0) so I'm closing as resolved.
Activity
shlomiassaf commentedon Nov 6, 2017
cc @tbosch @chuckjaz
@tbosch I think its an edge case of microsoft/TypeScript#17384 you didn't handle
Also, using TS 2.5.3 and 2.6.1 did not solve the problem.
shlomiassaf commentedon Nov 6, 2017
Another update to help identify the source:
It doesn't have to be a custom type, even intrinsic types will fail.
attach parent in setOriginalNode
shlomiassaf commentedon Nov 6, 2017
OK, for now, if by any change someone is interested, this is a working, monkey patching, workaround:
just import this file in the top of your webpack config module, or if you use
ngcinvoke it from a local file.kirillgroshkov commentedon Nov 7, 2017
waiting for the fix..
simonalbrecht commentedon Nov 8, 2017
Any tips on how to integrate this fix into an
@angular/cli@1.5.0project without having tong eject?shlomiassaf commentedon Nov 20, 2017
create a local
ngexecutable that acts as a pass-through.It will run the workaround first, then pass control to the original ng script.
Assuming the following file is in the root of the project:
Filename: ng
Did not test it, but should work.
Maybe some modifications based on OS.
You can also add it to your package.json scripts
niveo commentedon Nov 22, 2017
microsoft/TypeScript#17384
niveo commentedon Nov 28, 2017
typestack/class-transformer#108
@rmrevin
niveo commentedon Dec 15, 2017
angular/angular-cli#8434
@gmavritsakis
I had the same issue with:
Angular CLI 1.6.1
Typescript 2.4.2
Angular 5.0.2
Found a solution by changing typescript.js for now.
Replace all the function
function nodeCanBeDecorated(node)
with the following code
Which comes from here, if you compile typescript:
shlomiassaf/TypeScript@7017fa2
kirillgroshkov commentedon Jan 13, 2018
I want to share my workaround that I put together after reading other advices here and there. It's patching an
ngscript from@angular/cli@1.6.4(current version at the moment of writing). Because of that it prevents updating@angular/cli, so be prepared.ngsomewhere in your repo. You can grab patched version from here:https://github.com/kirillgroshkov/angular-cli/blob/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1/packages/%40angular/cli/bin/ng
Here's what changed, compared to the original file: https://github.com/kirillgroshkov/angular-cli/commit/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1
postinstallscript in yourpackage.jsonthat will run every time after you donpm install(oryarn install) and copy/overwritengfrom your location tonode_modules/@angular/cli/bin/ng.daixtrose commentedon Feb 9, 2018
@kirillgroshkov Your solution cannot be applied in my context (@angular 5.0.3)
any hints?
kirillgroshkov commentedon Feb 11, 2018
@daixtrose My solution is when
@angular/cliis used in the project. Seems you you don't use it (cause I can't see it in node_modules), then how do you compile your angular project? Anyway, if you dig deeper, you'll find what lines you need to add to your compiler script to make it work, good luck!ps: Lines are there, between 4 and 29:
https://github.com/kirillgroshkov/angular-cli/blob/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1/packages/%40angular/cli/bin/ng
splincode commentedon Apr 5, 2018
typestack/class-transformer#108
splincode commentedon Apr 5, 2018
Also not working in Angular
JoostK commentedon Mar 15, 2020
Apparently, this started working from Angular CLI 1.7 onwards, so somehow the CLI was involved. I can't reproduce this in newer versions of Angular (or even with Angular 5.0.0, TS 2.4.2 and CLI 1.7.0) so I'm closing as resolved.
angular-automatic-lock-bot commentedon Apr 15, 2020
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.