• module "pages/index/wx-server-sdk" is not defined


    1、错误描述

    VM542:1 thirdScriptError
    module "pages/index/wx-server-sdk" is not defined; [Component] Event Handler Error @ pages/index/index#bound submitData
    Error: module "pages/index/wx-server-sdk" is not defined
        at require (WAService.js:1:1353304)
        at WAService.js:1:1353055
        at ye.submitData (http://127.0.0.1:37728/appservice/pages/index/index.js:61:17)
        at Object.r.safeCallback (WAService.js:1:1088665)
        at WAService.js:1:1280762
        at r (WAService.js:1:1213062)
        at WAService.js:1:1213184
        at WAService.js:1:392894
        at n (http://127.0.0.1:37728/appservice/appservice?t=1567391947377:4092:27790)
        at e.exports.<anonymous> (http://127.0.0.1:37728/appservice/appservice?t=1567391947377:4092:28132)

    2、错误原因

         在调用微信小程序中的模块,生成二维码;需要用到wx-server-sdk模块,但是这个模块没有安装

    const cloud = require('wx-server-sdk')
        cloud.init()
        exports.main = async (event, context) => {
          try {
            const result = await cloud.openapi.wxacode.createQRCode({
              path: 'page/index/index',
               430
            })
            console.log(result)
            return result
          } catch (err) {
            console.log(err)
            return err
          }
        }

    3、解决办法

          使用npm安装wx-server-sdk

    npm install --save wx-server-sdk@latest

         但是问题是,本地微信小程序项目下没有package.json文件,无法安装

    Administrator@USER-0GUONPPBHK MINGW64 /f/wio
    $ npm install --save wx-server-sdk@latest
    
    > protobufjs@6.8.8 postinstall F:wio
    ode_modulesprotobufjs
    > node scripts/postinstall
    
    npm WARN saveError ENOENT: no such file or directory, open 'F:wiopackage.json'
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN enoent ENOENT: no such file or directory, open 'F:wiopackage.json'
    npm WARN wio No description
    npm WARN wio No repository field.
    npm WARN wio No README data
    npm WARN wio No license field.
    
    + wx-server-sdk@0.8.1
    added 77 packages from 157 contributors in 22.044s
    
  • 相关阅读:
    A1052. Linked List Sorting (25)
    A1032. Sharing (25)
    A1022. Digital Library (30)
    A1071. Speech Patterns (25)
    A1054. The Dominant Color (20)
    A1060. Are They Equal (25)
    A1063. Set Similarity (25)
    电子码表
    矩阵键盘
    对象追踪、临时对象追踪、绝对坐标与相对坐标
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313699.html
Copyright © 2020-2023  润新知