收藏
回答

请问一下,我的云函数突然不能本地调试了这是为什么?


开启本地调试失败
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这是报错信息,上一秒还在测试,下一秒啥操作没有就开始报错
回答关注问题邀请回答
收藏

2 个回答

  • 邓坤力
    邓坤力
    06-28

    本地没有 npm install got

    06-28
    有用
    回复 3
    • Hall of fame
      Hall of fame
      06-28
      莫得诶,要在云函数的终端位置命令下载一个是吗
      06-28
      回复
    • Hall of fame
      Hall of fame
      06-28
      安装完出现这东西
      06-28
      回复
    • Hall of fame
      Hall of fame
      06-28回复Hall of fame
      // 云函数模板
      // 部署:在 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
        }
      }
      06-28
      回复
  • Hall of fame
    Hall of fame
    06-28

    当我去调用: const got = require('got')这条语句之后就开始无法调试


    06-28
    有用
    回复
登录 后发表内容
问题标签