小程序Component is not found in path "path/to/vant-weapp/dist/button/index"

如果你遇到了這樣的問題

問題

jsEnginScriptError
Component is not found in path "pages/index/miniprogram_npm/vant-weapp/action-sheet" (using by "pages/index/index");onAppRoute
Error: Component is not found in path "pages/index/miniprogram_npm/vant-weapp/action-sheet" (using by "pages/index/index")
    at G (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1526161)
    at G (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1526365)
    at http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1547723
    at Module.Ue (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1548302)
    at Function.value (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1631292)
    at Tt (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1647404)
    at http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1651666
    at xt (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1652159)
    at Function.<anonymous> (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1655744)
    at i.<anonymous> (http://127.0.0.1:65059/appservice/__dev__/WAService.js:2:1624244)

微信截圖_20200301102856.png

請不要擔心,問題在於你錯誤的引用了npm包,並且路徑可能會出現錯誤

解決方案

1.首先確認是否安裝vant-weapp,安裝步驟如下:

1.1 執行npm init

1.2 回車到結束

1.3 npm i vant-weapp -S --production

1.4 工具->構建npm,這時你的文件目錄會生成miniprogram_npm中文件爲你所構建的Npm包

微信截圖_20200301103630.png

2.項目詳情->使用npm(如果報錯繼續執行第1.4步,構建npm)

3.查看 工具->項目詳情->ES6轉ES5是否√選,如果沒有,點擊勾選
微信截圖_20200301103606.png

  1. index.json放組件文件中,修改引用的組件miniprogram_npm中的內容

這裏說明一點,如果你採用的是TS項目,你需要在miniprogram中初始化npm,執行npm init而非項目根目錄

原文鏈接www.joynop.com/p/213.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章