我也碰到了,必须重新打开 本地调试
小程序云开发本地调试控制台报错“函数必须导出名为 'main' 的方法”bug勾选文件变更时自动重新加载,此bug在编辑数据库相关代码时出现,具体表现为输入一些字符如空格和删掉后,保存,就会出现以下信息。如果保存后报错,把代码改为创建新函数生成的模板代码仍会报错,另外,不只是修改数据库操作语句会产生此bug,反复按ctrl+s也有几率产生bug 安装依赖使用的命令是npm install --save wx-server-sdk@latest 代码: const cloud = require('wx-server-sdk') cloud.init() // 云函数入口函数 exports.main = async (e, context) => { const wxContext = cloud.getWXContext() var time=new Date() var type=e.type var deviceid=e.deviceid a={ time:time, type:type, deviceid:deviceid, read:false } const db = cloud.database() db.collection('announces').add({ data:a }) db.collection('userdevice').where({ deviceid:deviceid }).get().then( res=>{ console.log(res.data) } ) /*return { e, openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, aa:a }*/ } 报错信息: node.js:1 [error] Uncaught Exception: Error: 函数必须导出名为 'main' 的方法 at u.load (C:\Users\duchu\AppData\Roaming\Tencent\微信开发者工具\package.nw\js\common\cloud-functions-debugger-server\worker\node.js:1:22007) at u.reload (C:\Users\duchu\AppData\Roaming\Tencent\微信开发者工具\package.nw\js\common\cloud-functions-debugger-server\worker\node.js:1:26848) at C:\Users\duchu\AppData\Roaming\Tencent\微信开发者工具\package.nw\js\common\cloud-functions-debugger-server\worker\node.js:1:28280 at process. (C:\Users\duchu\AppData\Roaming\Tencent\微信开发者工具\package.nw\js\common\cloud-functions-debugger-server\worker\node.js:1:28356) at process.emit (events.js:203:13) at emit (internal/child_process.js:876:12) at processTicksAndRejections (internal/process/task_queues.js:77:11) m @ node.js:1 (anonymous) @ node.js:1 emit @ events.js:203 (anonymous) @ internal/process/execution.js:150 TickObject (async) init @ internal/inspector_async_hook.js:21 emitInitNative @ internal/async_hooks.js:134 emitInitScript @ internal/async_hooks.js:341 TickObject @ internal/process/task_queues.js:102 nextTick @ internal/process/task_queues.js:130 handleMessage @ internal/child_process.js:885 channel.onread @ internal/child_process.js:574
2020-04-09