You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 6升级至8.3.6后构建失败,请求技术支持

Fixing Angular 6 → 8 Upgrade Errors with Creative Tim Template

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):

  1. Run this command in your project root:
    npm install typescript@3.5.3 --save-dev
    
  2. Or manually update the typescript entry in your package.json to:
    "typescript": "~3.5.3"
    
    Then run npm install to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:13:06