微信小程序——找不到组件路径

本文介绍了在微信小程序开发中遇到组件路径找不到的问题,详细描述了解决过程,包括检查页面.json配置、确认js文件中component构造器的存在,最终发现问题是由于app.js中缺少获取设备信息的代码导致。

微信小程序——找不到组件路径(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();

增加上述代码后,保存后不报错了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值