微信小程序云开发 报错汇总(持续更新....)

微信小程序云开发 报错汇总(持续更新....)
云开发问题有点多,个人开发确实有点迷…

  1. 安装包版本太高

Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 7caa9d98-1bc1-11ea-afe4-5254003e0a60, cloud function service error code -504002, error message The “original” argument must be of type function; at cloud.callFunction api;

解决方法
云函数cloudfunctions目录下npm安装的依赖包的版本报错,我们一般是这样安装的
npm install {包名} --save
现在需要指定包的版本号,即 npm install {包名} @{版本号} --save

  1. wx-server-sdk不存在

Error: errCode: -404011 cloud function execution error Cannot find module ‘wx-server-sdk’

解决方法:
两种方式:

  1. 卸载现在的微信开发者工具,重新安装 稳定版 的微信开发者工具。官方说是低版本更新后存在的问题,其实并不是,本人使用的开发版最新版本的微信开发者工具也是同样的问题,而且严重的是不管怎么安装,就是提示“wx-server-sdk”

  2. 在 云函数 cloudfunctions根目录下打开终端安装wx-server-sdk
    npm install --save [email protected]
    然后,输入
    npm init -y
    初始化,再看package.json中是否已经写入wx-server-sdk

  3. 云函数访问第三方服务器,网页解析问题

Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 2204bbbf-35f6-11ea-8015-52540029942f, cloud function service error code -504002, error message stringify response to json failed: Converting circular structure to JSON; at cloud.callFunction api;

解决方法:

  1. 在小程序miniprogram目录下,云函数所对应的目录下的 .js文件 文件中修改 返回属性,并用 JSON.parse调用如

Page({
httpRequest:function(e){
wx.cloud.callFunction({ //调用云函数
name:‘httpRequest‘ //云函数名为http
}).then(res=>{       //Promise
console.log(JSON.parse(res.result))
})
},
})

  1. 在云函数 cloudfunctions 中的 httpRequest 函数中,指定返回类型,如

// 云函数入口文件
const cloud = require(‘wx-server-sdk’)
const got = require(‘got’)
cloud.init({
// API 调用都保持和云函数当前所在环境一致
env: cloud.DYNAMIC_CURRENT_ENV,
})
// 云函数入口函数
exports.main = async (event, context) => {
let response = await got(“https://www.baidu.com”)
return response.body
}

↓↓ 持续更新中… ↓↓
微信小程序云开发 报错汇总(持续更新....)