Angular 6升级至8.3.6后构建失败,请求技术支持
Hey there, let's work through the two errors you're facing after upgrading your Angular CLI from 6 to 8.3.6—they're both common hiccups when jumping between major Angular versions with third-party templates.
1. Sass Loader Error: Top-level selector cannot contain parent selector "&"
What's causing this?
The error points to &::-moz-placeholder in src\assets\scss\paper-dashboard\mixins\_inputs.scss line 25. Newer versions of sass-loader (bundled with Angular CLI 8) enforce stricter Sass syntax rules. The & parent selector can't be used at the top level of a mixin—it expects to be nested inside a parent selector when the mixin is included.
How to fix it:
Modify the problematic line in the mixin to use @at-root to properly resolve the parent selector:
// Replace this line: &::-moz-placeholder { @content; } // With this: @at-root #{&}::-moz-placeholder { @content; }
This tells Sass to generate the selector at the root level while still referencing the parent selector that the mixin is nested inside. Alternatively, double-check that you're only including this placeholder mixin within element selectors (like input, textarea) rather than calling it at the top level of your stylesheets.
2. TypeScript Version Mismatch with Angular Compiler
What's causing this?
Angular 8's compiler requires TypeScript versions >=3.4.0 and <3.6.0, but your package.json shows you're using TypeScript 3.6.3. This version conflict breaks the Angular build process.
How to fix it:
Downgrade TypeScript to a compatible version (e.g., 3.5.3, the latest stable release in the 3.5.x range):
- Run this command in your project root:
npm install typescript@3.5.3 --save-dev - Or manually update the
typescriptentry in yourpackage.jsonto:
Then run"typescript": "~3.5.3"npm installto apply the change.
Bonus: Avoid Future Upgrade Headaches
Using ng update --all --force can force incompatible dependencies to install, which often leads to issues like these. For major Angular version jumps (6 → 7 → 8), follow the official upgrade steps incrementally:
- First upgrade from Angular 6 to 7 with
ng update @angular/cli@7 @angular/core@7 - Then upgrade from 7 to 8 with
ng update @angular/cli@8 @angular/core@8
This ensures dependencies are upgraded in a compatible way without forcing mismatched versions.
Once you've applied these fixes, run ng serve -o again—it should work as expected!
内容的提问来源于stack exchange,提问作者AlexL

