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

MacOS/Chrome下Salesforce LWC本地开发服务器:Wire调用Apex报500错误

LWC本地开发服务器Wire调用Apex报aura.token缺失的500错误解决方法

问题现象

使用Salesforce本地开发服务器开发LWC时,通过@wire调用Apex函数出现500服务器错误,提示Missing parameter value for aura.token,但Lightning Data Service可正常在已连接的scratch org中创建记录,且代码部署到scratch org UI后能正常运行,排除代码本身问题,确定为本地开发服务器配置异常。

完整错误信息:

{"error":[{"message":"error parsing apex response: */{\"event\":{\"descriptor\":\"markup://aura:systemError\",\"attributes\":{\"values\":{\"message\":\"Missing parameter value for aura.token\",\"showOverride\":false}}},\"exceptionMessage\":\"Missing parameter value for aura.token\",\"exceptionEvent\":true}/*ERROR*/"}

排查与解决步骤

  • 重新确认本地认证状态
    运行sfdx force:auth:list检查默认scratch org是否处于已认证状态,若状态异常或默认环境不对,重新认证并设为默认:

    sfdx force:auth:web:login -d -a <你的scratch-org别名>
    
  • 清除本地服务器缓存
    停止本地开发服务器,删除项目根目录下的.localdevserver文件夹,然后重启服务器:

    sfdx force:lightning:lwc:start
    
  • 同步Apex类元数据与权限
    确保Apex类标注了@AuraEnabled(cacheable=true)(针对缓存型Wire调用),并重新部署Apex类到scratch org,保证本地服务器能获取最新元数据:

    sfdx force:source:deploy -p force-app/main/default/classes
    
  • 检查版本兼容性
    对比sfdx-cli版本与scratch org的API版本:

    • 查看sfdx-cli版本:sfdx --version
    • 查看scratch org API版本:sfdx force:org:display -u <你的scratch-org别名>
      若版本不一致,更新sfdx-cli或修改sfdx-project.json中的sourceApiVersion保持匹配。
  • 重置本地服务器会话
    停止服务器后,设置正确的默认用户并带--reset参数重启:

    sfdx force:config:set defaultusername=<你的scratch-org别名>
    sfdx force:lightning:lwc:start --reset
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 18:50:03