cordova打包出現Cannot read property 'toLowerCase' of undefined報錯的解決方案

最近跟新了xcode後,發現使用cordova項目打包app是出現了下面錯誤
Cannot read property ‘toLowerCase’ of undefined
在網上找了許久才找到解決方案,結果!!! 有出現了Cannot read property ''name" of undefined 的報錯,你他…,調試和查找許久,終於找到了問題所在和解決方案,現在記下來做個記錄

1. Cannot read property ‘toLowerCase’ of undefined

報錯位置://platforms/ios/cordova/lib/list-emulator-build-targets 第54行的device.availability.toLowerCase()
修改:

if (device.name === deviceType.name.replace(/\-inch/g, ' inch') &&
    device.availability.toLowerCase().indexOf('unavailable') < 0) {
    availAcc.push(device);
 }

改爲:

if (device.name === deviceType.name || device.name === deviceType.name.replace(/\-inch/g, ' inch')) {
     // Check new flag isAvailable (XCode 10.1+) or legacy string availability (XCode 10 and lower)
     if (device.isAvailable || (device.availability && device.availability.toLowerCase().indexOf('unavailable') < 0)) {
          availAcc.push(device);
      }
  } 

參考自https://www.cnblogs.com/oliverreal/p/9859343.html

2. Cannot read property ''name" of undefined

如果你是按照上面的參考鏈接中的方法來修改就會設置再打包的時候就會出現這個錯誤
報錯位置:/platforms/ios/cordova/lib/build.js 的第68行,如下圖:

原因:在/platforms/ios/cordova/lib/list-emulator-build-targets文件中的第55行中的device.isAvailable 的值不再是 YESNO 了,而變成了truefalse ,使用在build.js 中拿不到數據

修改:將device.isAvailable == "YES" 改爲 device.isAvailable 或加上 || device.isAvailable === true

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