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

Salesforce LWC本地开发服务器启动超时崩溃问题求助

解决LWC本地开发启动超时退出问题

问题现象

执行sfdx force:lightning:lwc:start后,日志输出以下内容后触发超时错误:

[HPM] 创建代理:/ -> https://ability-customization-2906-dev-ed.my.salesforce.com
[HPM] 订阅http-proxy事件:['proxyReq', 'error', 'close']
cp: 找不到文件或目录:/Users/admin/Desktop/suman/force-app/main/default/staticresources/*
cp: 找不到文件或目录:/Users/admin/Desktop/suman/force-app/main/default/contentassets/*
LWR6003: 监听端口:3333
服务器已启动:http://localhost:3333
LWR6000: 创建版本哈希"f5aff7264b"
LWR6001: 写入文件/Users/admin/Desktop/suman/.localdevserver/webruntime/custom-component/f617504cf1/dev/en-GB/c/myfirstLwc.js...

最终提示CLIError: timed out,服务器意外退出,命令以退出码1结束。

解决方案

1. 补全缺失的目录

日志中的cp错误源于staticresources和contentassets目录不存在,服务器尝试复制文件失败可能阻塞后续流程导致超时:

  • 手动创建缺失目录:
    mkdir -p /Users/admin/Desktop/suman/force-app/main/default/staticresources
    mkdir -p /Users/admin/Desktop/suman/force-app/main/default/contentassets
    
  • 若无需目录内容,可在目录内创建空的.gitkeep文件(Git管理场景下),避免后续重复触发找不到目录的错误。

2. 更新SFDX CLI并适配API版本

当前使用的API版本49.0对应旧版LWC本地开发工具,存在已知超时风险:

  • 更新SFDX CLI到最新稳定版:
    sfdx update
    
  • 若更新后问题仍存在,尝试指定更高API版本启动服务器(如57.0+):
    sfdx force:lightning:lwc:start -v 57.0
    

3. 验证网络连接与用户权限

服务器代理指向Salesforce org,网络拦截或权限不足可能引发超时:

  • 测试本地到https://ability-customization-2906-dev-ed.my.salesforce.com的网络连通性,确认无防火墙/代理拦截。
  • 检查登录用户test-lgcvzacysqx3@example.com的权限:需拥有Lightning Component Bundle相关权限,以及访问本地开发服务器的权限。

4. 清理本地开发缓存

旧缓存文件可能导致写入或加载异常:

  • 删除.localdevserver目录:
    rm -rf /Users/admin/Desktop/suman/.localdevserver
    
  • 重新启动LWC本地开发服务器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 16:36:22