收藏
回答

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'"}



最后一次编辑于  2018-09-11  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏关注问题回答

7 个回答