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',
width: 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\node_modules\protobufjs
> node scripts/postinstall
npm WARN saveError ENOENT: no such file or directory, open 'F:\wio\package.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:\wio\package.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