微信小程序——找不到组件路径(Component is not found in path…)
问题描述
新建了一个小程序项目,导入一个github上的tabbar组件,结果发现报错——
VM2444:1 jsEnginScriptError
Component is not found in path "tabbarComponent/tabbar" (using by "pages/index/index");onAppRoute
Error: Component is not found in path "tabbarComponent/tabbar" (using by "pages/index/index")
at G (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1466011)
at G (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1466215)
at http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1487255
at Module.We (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1487834)
at Function.value (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1572211)
at Tt (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1588012)
at http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1592274
at xt (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1592767)
at Function.<anonymous> (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1596300)
at i.<anonymous> (http://127.0.0.1:11569/appservice/__dev__/WAService.js:1:1565163)
解决历程
首先想到的就是应用到组件的页面的.json文件(index.json、middle.json……)中组件的路径填写有误。但是检查了几遍,确认路径无误。百度了一下情况,发现也可能是页面js文件中没有component构造器的原因,然而再次确认之后这个可能也排除了。
最后下载了组件的演示代码,逐个文件比对……发现问题出在app.js文件中。之前新建的项目中,app.js缺少了获取设备信息的代码——
getSystemInfo: function () {
let t = this;
wx.getSystemInfo({
success: function (res) {
t.globalData.systemInfo = res;
}
});
},
在onLaunch函数中再增加
//获取设备信息
this.getSystemInfo();
增加上述代码后,保存后不报错了。