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

Angular 6.0.1引入ng-zorro-antd报错:无法找到指定less文件

解决Angular 6.0.1引入ng-zorro-antd时的模块找不到错误

结合你的Angular版本和报错信息,问题主要出在版本不兼容和样式文件路径错误上,我来一步步帮你搞定:

1. 安装适配Angular 6的ng-zorro-antd版本

Angular 6.0.1对应的ng-zorro-antd版本是1.x系列,你直接用npm install ng-zorro-antd --save会默认安装最新版(当前已到17+),完全不兼容Angular 6,这才导致找不到指定的less文件。

先卸载当前版本:

npm uninstall ng-zorro-antd --save

然后安装适配的稳定版:

npm install ng-zorro-antd@1.8.1 --save

2. 修正angular.json中的样式路径

在ng-zorro 1.x版本中,样式文件并不在src子目录下,而是直接放在包的根目录。你需要把angular.json里的styles数组修改为:

"styles": [
  "../node_modules/ng-zorro-antd/ng-zorro-antd.less",
  "src/styles.css"
]

注意去掉路径里的src/部分,这个版本的样式文件是直接放在node_modules/ng-zorro-antd/根目录下的。

3. 补充Less处理依赖

Angular 6处理Less文件需要依赖less和适配版本的less-loader,如果你的项目还没装,执行以下命令安装:

npm install less less-loader@4.1.0 --save-dev

4. 重启Angular开发服务

修改完配置和依赖后,一定要重启你的Angular CLI服务,让配置生效:

ng serve --open

另外你在模块中导入NgZorroAntdModule.forRoot()的操作是正确的,保持这个配置就好。做完以上步骤,模块找不到的错误应该就能解决了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:49:10