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

Angular6项目构建失败:找不到node-sass模块求助

解决Angular 6构建报错:Cannot find module 'node-sass'

核心原因

Angular 6的官方构建工具@angular-devkit/build-angular隐式依赖node-sass,即使你的package.json里没显式声明,底层也需要这个包。你尝试的Node12/16版本和Angular 6的依赖生态不兼容,这是问题关键——Angular 6仅支持Node.js 8.9+,推荐用8.x或10.x的LTS版本。

具体解决步骤

  • 切换到兼容的Node版本:
    用nvm(版本管理工具)切换的话,执行:

    nvm install 10.24.1
    nvm use 10.24.1
    

    没有nvm的话,直接去Node官网下载10.x的LTS版本安装即可。

  • 清理旧依赖与缓存:

    # 删除node_modules文件夹(Mac/Linux)
    rm -rf node_modules
    # Windows系统执行这个:rd /s /q node_modules
    
    # 删除锁文件
    rm package-lock.json
    
    # 强制清除npm缓存
    npm cache clean --force
    
  • 显式安装适配的node-sass版本并重新安装依赖:
    Angular 6对应node-sass的4.x版本,执行:

    npm install node-sass@4.14.1 --save-dev
    npm install
    
  • 重新构建项目:

    ng build
    

内容的提问来源于stack exchange,提问作者Jobz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 21:25:43