测试时候出现is not a function
发布于 5 年前 作者 zliao 7009 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

{“errorCode”:1,“errorMessage”:“user code exception caught”,“stackTrace”:“TypeError: this.realHandler is not a function\n    at EventHandler.handle (/var/runtime/node8/bootstrap.js:243:28)\n    at invoke (/var/runtime/node8/bootstrap.js:118:22)\n    at Timeout.setTimeout [as _onTimeout] (/var/runtime/node8/bootstrap.js:61:9)\n    at ontimeout (timers.js:475:11)\n    at tryOnTimeout (timers.js:310:5)\n    at Timer.listOnTimeout (timers.js:270:5)”}

  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

开发工具v1.02.1904091

在开发工具快速创建的项目中点击->快速新建云函数->复制sum代码->在云端控制器中新建云函数->同步到本地->复制index.js和package.json->将sun代码复制到index.js。点击开发工具中模拟界面的测试云函数,提示调用失败,在云端控制器看到以上错误信息。

index.js

// 云函数入口文件

const cloud = require(‘wx-server-sdk’)

cloud.init()

// 云函数入口函数

exports.main = (event, context) => {

console.log(event)

console.log(context)

return {

sum: event.a + event.b

}

}

package.json

{

“name”: “sum”,

“version”: “1.0.0”,

“description”: “”,

“main”: “index.js”,

“scripts”: {

“test”: “echo \“Error: no test specified\” && exit 1”

},

“author”: “”,

“license”: “ISC”,

“dependencies”: {

“wx-server-sdk”: “latest”

}

}

回到顶部