本来一直正常开发,结果突然出现-504002错误,
错误的症状是:
1、显示如下错误信息。
2、调试器->Network模式下,函数调用记录显示500错误。
3、表现为正常的任何云函数无法执行。
Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: 145 code exit unexpected 请前往云开发AI小助手查看问题:https://tcb.cloud.tencent.com/dev#/helper/copilot?q=FUNCTIONS_EXECUTE_FAIL (callId: 1743865175481-0.31513388579739976) (trace: 22:59:35 start->22:59:38 normal poll->22:59:40 system error (Error: errCode: -504002 functions execute fail | errMsg: 145 code exit unexpected 请前往云开发AI小助手查看问题:https://tcb.cloud.tencent.com/dev#/helper/copilot?q=FUNCTIONS_EXECUTE_FAIL), abort)
at L (<anonymous>:1:320008)
at <anonymous>:1:355989(env: Windows,mp,1.06.2412050; lib: 3.6.6)
错误的原因:
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
函数的运行环境被后台清除了(初步判断是被微信后台自动清除的,并不是用户自己清除的)
解决办法是:
在小程序内调用另一个独立的旧函数,旧函数如果执行正常,则当前函数就能自动恢复正常。
如果没有可用的旧函数,则需要新建一个云函数,内容简单,但是需要上传并部署所有文件,包括node_modules和package.json文件,小程序调用正常后,即可。