云函数代码:
// 云函数入口文件
const cloud = require('wx-server-sdk')
const got = require('got')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
}
}
package.json
{
"name": "http",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"got": "^12.0.1",
"wx-server-sdk": "^2.5.3"
}
}
报错信息:
Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID
84e73b60-fce3-49b8-ae13-b74247eaa248, cloud function service error code -504002, error message Runtime.
ImportModuleError: Error: Cannot find module 'got'Require stack:
- /var/user/index.js
- /var/runtime/node12/UserFunction.js
- /var/runtime/node12/Runtime.engine.js
- /var/runtime/node12/bootstrap.js
at Object.module.exports.load (:20392/var/runtime/node12/UserFunction.js:34)
at Runtime.handleOnce (:20392/var/runtime/node12/Runtime.engine.js:99)
at Timeout._onTimeout (:20392/var/runtime/node12/Runtime.engine.js:56)
at listOnTimeout (:20392/appservice/internal/timers.js:549)
at processTimers (:20392/appservice/internal/timers.js:492); at cloud.callFunction api;
at new e (VM54 WAService.js:26)
at s (VM54 WAService.js:26)
at c (VM54 WAService.js:26)
at Function.success (VM54 WAService.js:26)
at I (VM54 WAService.js:2)
at VM54 WAService.js:2
at u (VM54 WAService.js:35)
at Function.<anonymous> (VM54 WAService.js:35)
at I (VM54 WAService.js:2)
at VM54 WAService.js:2(env: Windows,mp,1.05.2110290; lib: 2.14.1)
我也遇到了 解决了嘛 楼主
npm install got
2.我想请教一下,小程序请求后台微服务是放到云函数中还是小程序中合适~有什么说法吗?
3.如果是云函数那么什么组件合适找了半天感觉got还在维护~~~
2.之前百度说有的组件已经停止更新了,而got更新迭代还是一周前