uni-app mac os hbuilder unicloud bug

uni-app mac os hbuilder unicloud bug

开发环境 版本号 项目创建方式
HbuilderX 3.1.2

操作步骤:

  • 请求所有到云函数都会出现

预期结果:

{"requestId":"e60a821e-6e12-11eb-ae67-525400e7bfe4","data":{"response_data":"{\"state\":200,\"mgs\":\"成功\",\"data\":[]}"}

实际结果:

{"code":"FUNCTIONS_EXECUTE_FAIL","message":"Unexpected token u in JSON at position 0\nSyntaxError: Unexpected token u in JSON at position 0\n    at JSON.parse (<anonymous>)\n    at exports.main (/var/user/__index.js:6:39)\n    at EventHandler.exports.main [as realHandler] (/var/user/index.js:106:21)\n    at EventHandler.handle (/var/runtime/node8/bootstrap.js:427:28)\n    at invoke (/var/runtime/node8/bootstrap.js:225:22)\n    at Timeout.setTimeout [as _onTimeout] (/var/runtime/node8/bootstrap.js:150:9)\n    at ontimeout (timers.js:475:11)\n    at tryOnTimeout (timers.js:310:5)\n    at Timer.listOnTimeout (timers.js:270:5)","requestId":"0ec73c12c4bb1"}

更多关于uni-app mac os hbuilder unicloud bug的实战教程也可以访问 https://www.itying.com/category-93-b0.html

8 回复

测试未复现。连接的本地云函数还是云端云函数?运行到哪端?可以提供一下示例工程吗

更多关于uni-app mac os hbuilder unicloud bug的实战教程也可以访问 https://www.itying.com/category-93-b0.html


云端,h5,我要怎么上传示例工程呢

window HBuilderX 3.1.2也有同样的问题

回复 1***@qq.com: 截图我看一下你的云函数入口文件

回复 DCloud_uniCloud_WYQ: 我找到解决到方法了,就是把云函数重新上传一遍就好了,但是切换电脑又得重新上传才不会报错。。。

3.0.5的版本就不会出现这样的问题啊

回复 1***@qq.com: 看一下network面板请求云函数对应的请求体,发出来一下

这个错误表明云函数在解析JSON数据时遇到了问题,错误信息"Unexpected token u in JSON at position 0"通常意味着传递给JSON.parse()的参数不是有效的JSON字符串,而可能是undefined。

常见原因及解决方案:

  1. 云函数接收到的event参数不是JSON格式
  • 检查客户端调用云函数时是否正确传递了参数
  • 确保调用时使用了uniCloud.callFunction()方法
  1. 云函数代码问题
  • 检查云函数入口文件是否正确处理了event参数
  • 确保在云函数中正确解析了传入参数
  1. 客户端调用代码示例:
uniCloud.callFunction({
  name: 'yourFunctionName',
  data: { /* 你的参数 */ }
})
  1. 云函数代码示例:
exports.main = async (event, context) => {
  try {
    // 处理逻辑
    return {
      state: 200,
      msg: '成功',
      data: []
    }
  } catch (e) {
    return {
      state: 500,
      msg: e.message
    }
  }
}
回到顶部