开启本地调试失败
worker for function code2 crashed with error code: 1 (Uncaught Fatal Exception)
加载执行入口文件失败,错误如下 Error: Cannot find module 'got'
Require stack:
- C:\Users\ASUS\WeChatProjects\miniprogram-16\cloudfunctions\code2\index.js
- C:\Users\ASUS\AppData\Roaming\Tencent\微信开发者工具\package.nw\js\common\cloud-functions-debugger-server\worker\node.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
at Function.Module._load (internal/modules/cjs/loader.js:527:27)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (C:\Users\ASUS\WeChatProjects\miniprogram-16\cloudfunctions\code2\index.js:3:11)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\ASUS\\WeChatProjects\\miniprogram-16\\cloudfunctions\\code2\\index.js',
'C:\\Users\\ASUS\\AppData\\Roaming\\Tencent\\微信开发者工具\\package.nw\\js\\common\\cloud-functions-debugger-server\\worker\\node.js'
]
}
z这是报错信息,上一秒还在测试,下一秒啥操作没有就开始报错
本地没有 npm install got
// 部署:在 cloud-functions/login 文件夹右击选择 “上传并部署”
const cloud = require('wx-server-sdk')
const got = require('got')
// 初始化 cloud
cloud.init({
// API 调用都保持和云函数当前所在环境一致
env: cloud.DYNAMIC_CURRENT_ENV
})
exports.main = async (event, context) => {
try {
console.log(event)
const page = event.page
const scene = event.scene
//appid和秘钥
const appid = '***',
secret = '***';
console.log(appid+secret);
// let AccessToken_options = await got('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx4be213e6cd487a&secret=wcyxpy12332')
const AccessToken_options =await got({
method: 'GET',
url: 'https://api.weixin.qq.com/cgi-bin/token',
qs: {
appid,
secret,
grant_type: 'client_credential'
},
json: true
});
//获取AccessToken
console.log(AccessToken_options)
const resultValue = await rp(AccessToken_options);
const token = resultValue.access_token;
//获取小程序码配置
const code_options = {
method: 'POST',
url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + token,
body: {
'page': page,
'width': 430,
'scene': scene
},
json: true,
encoding: null
};
//获取二进制图片
const buffer = await rp(code_options);
const upload = await cloud.uploadFile({
cloudPath: 'wxacode.png',
fileContent: buffer,
})
return {
wxacodefileID: upload.fileID
}
} catch (err) {
return err
}
}
这
同问,之前可以调试,今天突然就不能调试了
当我去调用: const got = require('got')这条语句之后就开始无法调试