Angular项目执行ng build时缺失目录报错求助
问题
[DEBUG] Failed to read directory "/Users/michael/Dev/versicherungrepository1/vp-1-frontend/angular:script/global:scripts": open /Users/michael/Dev/versicherungrepository1/vp-1-frontend/angular:script: no such file or directory
已执行的排查步骤:
- 临时停用多个库
- 检查angular.json文件
- 核对.env文件
项目angular.json的build配置片段:
"architect": { "build": { "builder": "@angular-devkit/build-angular:application", "options": { "outputPath": "/dist", "index": "src/index.html", "browser": "src/main.ts", "polyfills": ["zone.js"], "tsConfig": "tsconfig.app.json", "inlineStyleLanguage": "scss", "assets": ["src/favicon.ico", "src/assets"], "styles": [ "@angular/material/prebuilt-themes/indigo-pink.css", "src/my-theme.scss", "src/tailwind.css", "node_modules/swiper/swiper-bundle.min.css", "src/styles.scss" ], "scripts": [ "node_modules/swiper/swiper-bundle.min.js" ] }, "configurations": { "production": { "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "3mb" }, { "type": "anyComponentStyle", "maximumWarning": "2kb", "maximumError": "6kb" } ], "outputHashing": "all" }, "development": { "optimization": false, "extractLicenses": false, "sourceMap": true, "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.development.ts" } ] } }, "defaultConfiguration": "production" },
补充说明:该错误在本地系统、树莓派及虚拟服务器上均会出现,前两者会跳过错误继续执行,但虚拟服务器因性能不足无法继续构建。
解决方案
错误路径里的angular:script/global:scripts包含冒号,这不是合法的文件路径格式,说明是某个配置中的变量(模板变量、环境变量等)未被正确解析,被当作字面路径读取导致的问题。可按以下步骤排查解决:
- 全面检查项目内所有配置文件(包括tailwind.config.js、postcss.config.js、package.json、自定义webpack配置等),查找是否有引用
angular:script/global:scripts的地方,大概率是某个插件或工具的配置项错误,把变量名直接写进了路径配置。 - 检查第三方库的自定义配置(比如swiper、Angular Material的相关配置文件),确认是否有误写的路径配置。
- 再次核对.env文件及其他环境配置文件,确保没有定义错误的路径变量,导致构建时被错误替换成这个无效路径。
- 清理缓存并重装依赖:
- 执行
ng cache clean清理Angular缓存 - 删除
node_modules文件夹和package-lock.json文件 - 运行
npm install重新安装依赖 - 再次执行
ng build尝试构建
- 执行
- 如果项目使用了自定义webpack配置,检查配置中是否有错误引入该路径的代码。
内容的提问来源于stack exchange,提问作者Michael Fischer
相关产品推荐
相关产品推荐

