Closed entith closed 4 years ago
AFAICS the error occurs because incremental rebuilds run the type checker in a separate process, in which the custom Webpack rules are not applied. So the template file that gets loaded is really just the raw pug template itself, such that the ngFor
element is not expanded, leaving the {{item}}
as the only Angular template syntax.
@angular-builders/custom-webpack
is an external extension to the CLI and any customization achieved with it may cause incompatibility issues such as these.
As @JoostK mentioned in the fork type checker we only accept raw HTML and SVG templates.
What you can do to solve the issue is to disable fork type checking.
Thanks for the replies, I know this isn't exactly a supported configuration so I appreciate it!
Disabling the fork type checker did indeed resolve the issue. For anyone reading this that doesn't know how, I added "forkTypeChecker": false
to the build option in angular.json
.
...
"architect": {
"build": {
"options": {
"forkTypeChecker": false,
...
}
}
}
...
The downside now is that with my tiny one component demo application, the incremental rebuild jumped from around 225ms to 1250ms.
Is there any reasonable way to add custom rules to the Webpack config the forked type checker uses?
The forked type checker does not use Webpack so unfortunately there is no Webpack config to augment. However, the new Angular Webpack compiler plugin (PR) currently in development does not use the forked type checker. The new plugin will as a result resolve this issue without the build performance degradation. Please note though that the earliest the new plugin will be included for default use would be v11.
Great! Glad to hear us difficult folk's nonsense will continue to work.
I will probably stick with Angular 8 for now and keep an eye on that PR/v11.
Thanks for the help and explanations!
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.
π Bug report
Command (mark with an
x
)Is this a regression?
Yes, had no issues in Angular 8. I'm guessing this has something to do with Ivy.
Description
TS component:
Pug template:
I have the above example component and template in an Angular project.
The project builds without issue using
ng build
andng-build --prod
The dev server starts without any issues using
ng serve
and the page renders as expected.Once I start making changes to the project and the dev server automatically rebuilds, it prints the following error:
Property 'item' does not exist on type 'TestComponent'. Did you mean 'items'?
The Angular application does appear to continue to work correctly and auto-rebuild on changes (printing that error every time), but these false errors can potentially hide legitimate ones.
This happens with any variables generated with
*ngIf
or*ngFor
.div(*ngIf="name$ | async as name") {{name}}
: the{{name}}
portion will generate an errorThis issue occurs in both Angular 9 and 10.
I have tried two different methods of adding pug support to my project, the error occurs with both:
apply-loader
andpug-loader
)π¬ Minimal Reproduction
Here is a repository resulting from the below steps: https://github.com/entith/ng-cli-pug-template-variable-issue
ng new test --minimal --skip-tests --style sass --routing
cd test
npm i -D @angular-builders/custom-webpack pug pug-loader apply-loader
custom-webpack.config.js
file belowangular.json
as per the@angular-builders/custom-webpack
documentation to usecustom-webpack.config.js
ng g component test
ng serve
and wait for project to buildtest.component.pug
file: Compiled successfully
, and then a moment later the error should printitems
array in the component, the page should correctly reflect these changescustom-webpack.config.js
:π₯ Exception or Error
π Your Environment