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

Angular 17升级后@nx/web:file-server路径配置问题求助

解决Angular 17升级后@nx/web:file-server路径异常问题

Angular 17默认将构建产物输出到/dist/apps/[my-app-name]/browser/目录下,这和Angular 16的结构差异导致了静态资源路径匹配错误。你可以通过以下方式修改@nx/web:file-server的配置,让服务直接指向browser目录:

直接指定静态文件根目录

在project.json的serve-static配置中添加staticFilePath选项,明确指向browser子目录:

[...]
"serve-static": {
  "executor": "@nx/web:file-server",
  "options": {
    "buildTarget": "[my-app-name]:build",
    "staticFilePath": "dist/apps/[my-app-name]/browser"
  }
},
[...]

修改后执行原命令npx nx serve-static [my-app-name],此时服务的根目录就是browser文件夹,访问http://localhost:4200/en/即可正常加载所有静态资源,不会再出现404错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 13:32:12