错误:构建iOS Cordova时无法读取未定义的属性'replace' [英] Error: Cannot read property 'replace' of undefined when building iOS Cordova
问题描述
我使用创建了一个cordova项目cordova创建项目hello com.hello Hello
。
并添加了iOS平台使用 cordova平台添加iOS
。
在 cordova build ios
之后尝试做 cordova run ios
。
And added iOS platform using cordova platform add iOS
.
And tried to do cordova run ios
after cordova build ios
.
但它显示了我的错误(我用--d / --verbose来获取详细信息)。
But it shows me this error(I used --d/ --verbose to get the details).
/ usr / bin / codesign --force --sign - --timestamp = none
/Volumes/Untitled/Plot/PlotReel/platforms/ios/build/emulator/PlotReel.app
/ Volumes / Untitled / Plot / PlotReel / platforms / ios / build / emulator / PlotReel.app:
替换现有签名
/usr/bin/codesign --force --sign - --timestamp=none /Volumes/Untitled/Plot/PlotReel/platforms/ios/build/emulator/PlotReel.app /Volumes/Untitled/Plot/PlotReel/platforms/ios/build/emulator/PlotReel.app: replacing existing signature
** BUILD SUCCEEDED **
** BUILD SUCCEEDED **
找不到钩子before_deploy的脚本。错误:TypeError:不能
在删除时读取未定义的属性'replace'
No scripts found for hook "before_deploy". Error: TypeError: Cannot read property 'replace' of undefined
at remove (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:282:70)
at Array.forEach (native)
at Object.getdevicetypes (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:292:22)
at Object.listEmulatorImages [as run] (/Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/list-emulator-images:34:29)
at deployToSim (/Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/run.js:146:50)
at /Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/run.js:88:20
at _fulfilled (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:796:13)
at /Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:604:44
我已经尝试再次卸载和安装cordova,但问题仍然存在。
I have tried uninstalling and installing cordova again, but the problem is still remaining.
请帮助我。
推荐答案
新解决方案
此问题已在最新版本中修复版本的ios-sim软件包(所以现在这可能是更简单的解决方案 - 与下面列出的旧软件相比)。为了将ios-sim软件包更新到最新版本,请在终端/ cmd中运行:
This issue is fixed in the latest version of the "ios-sim" package (so now this is probably the easier solution - compared to the old one which is listed below). In order to update the "ios-sim" package to the latest version run this in your terminal/cmd:
cd platforms/ios/cordova/node_modules/
sudo npm install -g ios-sim@latest
旧解决方案
问题是 name_id_map [deviceName]
返回 undefined
表示 iPad Pro(12.9英寸)和 iPad Pro(10.5英寸)。
您可以使用 console.log('name_id_map [deviceName]:'+ name_id_map [deviceName]);
。
我通过添加if语句来修复此错误,该语句检查设备是否在 platforms / ios / cordova / node_modules / ios-sim / src / lib中定义。 js:282 。
I fixed this bug by adding an if statements which checks if the device is defined in "platforms/ios/cordova/node_modules/ios-sim/src/lib.js:282".
我更换了这个:
list = [];
var remove = function(runtime) {
// remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
};
这个:
list = [];
var remove = function(runtime) {
// remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
if (name_id_map[deviceName] && runtime) {
list.push(util.format('%s, %s', name_id_map[deviceName].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
}
};
iPad Pro(10.5英寸)模拟器不在列表中(但它无论如何都不会工作 - 没有检查)。
The "iPad Pro (10.5-inch)" simulator won't be on the list (but it doesn't probably work anyway - didn't check).
关于github的错误报告: https://github.com/phonegap/ios-sim/issues/210
Bug report on github: https://github.com/phonegap/ios-sim/issues/210
这篇关于错误:构建iOS Cordova时无法读取未定义的属性'replace'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!