Angular 13: document config changes necessary when using @ngtools/webpack
See original GitHub issueHi,
When trying to update my angular app built using @ngtools/webpack from angular 12 to the upcoming angular 13, I get the following error at runtime:
JIT compilation failed for injectable
class PlatformLocation {}
core.mjs:4060
Uncaught Error: The injectable 'PlatformLocation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
The injectable is part of a library that has been partially compiled.
However, the Angular Linker has not processed the library such that JIT compilation is used as fallback.
Ideally, the library is processed using the Angular Linker to become fully AOT compiled.
Alternatively, the JIT compiler should be loaded by bootstrapping using '@angular/platform-browser-dynamic' or '@angular/platform-server',
or manually provide the compiler with 'import "@angular/compiler";' before bootstrapping.
Angular 3
Webpack 9
core.mjs:4079
The same project works fine when built with angular 12.x (with no other change than a minor adjustment in webpack.config.mjs) so it looks like a regression.
I made a minimal self-contained repository to reproduce the issue at https://github.com/vanackere/ngtools-webpack-bug
To reproduce, simply run npm run dev
then npm run serve
Thanks by advance for looking at this !
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:37 (28 by maintainers)
Top Results From Across the Web
Webpack Tutorial: Understanding @ngtools/ ...
I've used Angular CLI successfully here at ag-Grid to build applications with AOT and found it very easy to use, but sometimes you...
Read more >ngtools/webpack
Webpack plugin that AoT compiles your Angular components and modules.. Latest version: 15.0.4, last published: 10 days ago. Start using ...
Read more >Angular 2, @ngtools/webpack, AOT
This is my tsconfig-aot.json which I',m using in one of my Angular 2 projects: { "compilerOptions": { "target": "es5", "module": "commonjs", ...
Read more >Webpack: an introduction - ts - GUIDE
Change the configuration so that it has two entry points, main.ts and vendor.ts : ... Rules tell Webpack which loaders to use for...
Read more >Building an App from Scratch with Angular and Webpack
We build an Single Page AngularJS App and bundle it using webpack ... Next we need to create a webpack.config.js file for our...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Angular libraries are compiled into partial compilation output, which is not yet fully AOT compiled. If the linker is not involved during the final build then there is a fallback available using the JIT compiler, which is likely what you’re seeing.
You may be missing some key points about ngcc and how using Babel does not have these limitations.
First, ngcc mutates the
node_modules
directory to store its built artifacts, which is incompatible with package managers such as pnpm/Yarn PnP. Secondly, the output of ngcc can hardly be cached. Any changes to thenode_modules
tree would invalidate its output, as there is no clear set of inputs that can be used as cache key (apart from the full lock-file of thenode_modules
installation). Thirdly, ngcc does not parallelize as effectively as Babel can, as ngcc requires topological sorting of its build tasks.None of these are issues with the linker approach. The linker is able to process a single input file independently, making parallelization and caching more effective. Granted, you have to configure your Babel plugin integration to actually use caching.
I don’t get it. Why do we suddenly have to use Babel when
ngcc
used to work fine? I am getting the error “The injectable ‘PlatformLocation’ needs to be compiled using the JIT compiler, but ‘@angular/compiler’ is not available.” and nothing makes any sense. Why would Angular libraries trigger the error? Aren’t they supposed to be AOT compatible now?Switching
ngcc
for Babel would be a REALLY BAD trade as whilengcc
runs once per node modules installation, babel runs every time.