Angular Material中Sass-migrator迁移@import至@use时路径错误解决
解决sass-migrator迁移Angular Material样式时找不到@angular/material的问题
问题原因
sass-migrator工具默认不会自动识别node_modules目录下的第三方包路径,因此当迁移涉及@use '@angular/material'这类引用时,会触发“找不到文件”的错误。
修正后的迁移命令
需要在命令中添加--load-path参数指定node_modules目录,让工具能定位到Angular Material的Sass文件。
基础场景(样式文件在项目根目录)
sass-migrator module --load-path=node_modules sample.scss
样式文件在子目录场景(比如src/styles下)
sass-migrator module --load-path=node_modules src/styles/sample.scss
补充说明
--load-path支持指定多个路径,用逗号分隔即可,比如同时包含自定义样式目录和node_modules:--load-path=node_modules,src/styles/custom- 迁移完成后,建议检查生成的
@use语法,确认是否保留了as mat这类别名配置,保证Angular Material的样式变量、混合宏能正常调用
内容的提问来源于stack exchange,提问作者LeO
相关产品推荐
相关产品推荐

