[图片] 我的云函数先后上传并部署了两个,后一个是自命名为userLogin的云函数。如图所示的是其package.json文件内容。在description里加入任何一个字段(不为空),即可在云端成功调用
Cannot find module 'wx-server-sdk简单尝试下云函数 [代码]'use strict'[代码][代码];[代码][代码]const cloud = require([代码][代码]'wx-server-sdk'[代码][代码]);[代码][代码]cloud.init({[代码][代码] [代码][代码]env: [代码][代码]'demo'[代码][代码]});[代码][代码]exports.main = (event, context, callback) => {[代码] [代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]db.collection([代码][代码]'user'[代码][代码]).add({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]username: [代码][代码]"learn cloud database"[代码][代码],[代码][代码] [代码][代码]password: [代码][代码]"www"[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.error(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]var[代码] [代码]num1 = parseInt(event.a);[代码][代码] [代码][代码]var[代码] [代码]num2 = parseInt(event.b);[代码][代码] [代码][代码]var[代码] [代码]result=num1+num2;[代码][代码] [代码][代码]event.sum=result;[代码][代码] [代码][代码]console.log([代码][代码]"key:"[代码] [代码]+ event.a);[代码][代码] [代码][代码]console.log([代码][代码]"Hello World"[代码][代码])[代码][代码] [代码][代码]console.log(event)[代码][代码] [代码][代码]console.log(event[[代码][代码]"non-exist"[代码][代码]])[代码][代码] [代码][代码]console.log(context);[代码][代码] [代码][代码]event.msg=[代码][代码]"hello"[代码][代码];[代码][代码] [代码][代码]callback([代码][代码]null[代码][代码], event);[代码][代码]};[代码] 运行的时候出现 返回结果: {"errorCode":10004,"errorMessage":"user code exception caught","stackTrace":"Cannot find module 'wx-server-sdk'"}
2021-06-12