Angular 8执行ng build prod报错,Ng2CompleterModule无法解析@angular/http
Hey there, I totally get how frustrating it is to hit these third-party library snags after an Angular version migration! Let's break down what's happening and fix this step by step:
The Root Cause
You’re right that Angular 8 phased out the @angular/http module in favor of @angular/common/http, but the issue isn’t in your own code anymore—it’s with the Ng2CompleterModule you’re using. The version of this library currently in your project still depends on the old @angular/http module, which is why the template compiler is throwing that error even after you removed all references to @angular/http in your code.
Step-by-Step Fixes
Here’s what you can do to resolve this:
Upgrade ng2-completer to an Angular 8-compatible version
First, check the version ofng2-completerin yourpackage.json. The library has specific versions built for Angular 8+—install the latest compatible release with this command:npm install ng2-completer@latestIf you want to be precise, you can confirm the exact Angular 8-compatible version by checking the library’s GitHub repository or npm page (usually versions >=5.0.0 work with Angular 8).
Temporary workaround (if upgrading isn’t possible immediately)
If you can’t upgrade the library right now, you can temporarily install the Angular 8 version of@angular/httpto satisfy the dependency. Run this command:npm install @angular/http@8.2.14Note: This is just a stopgap—
@angular/httpis deprecated in Angular 8, so prioritize upgradingng2-completeras soon as possible to avoid future issues.Double-check for residual references
Do a quick sweep to make sure there are no leftover imports of@angular/httpin yourapp.module.tsor component files, and that yourtsconfig.json/angular.jsondon’t have any configuration pointing to the old module.
Verify the Fix
After making the above changes, run your production build command again:
node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --aot --prod
This should resolve the template compile error from Ng2CompleterModule.
内容的提问来源于stack exchange,提问作者user14167994

