Salesforce 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

