Cordova Build在OS X上使用EACCES和ENOENT失败

kri*_*ath 3 macos node.js ios cordova

我最近开始使用Cordova构建iOS应用程序,但我遇到了障碍.在安装了nodeJS,git和cordova(使用sudo)之后,我在我的用户帐户的Documents文件夹中创建了我的第一个应用程序.

第一轮比赛完美无缺.一切正常,将我的开发帐户添加到Xcode帮助我的应用程序在设备上运行.我决定通过添加一个名为001_c.jsin 的"before_prepare"钩子来增加一些东西<appName>/hooks/before_prepare folder.这是钩子开始的方式:

//This is where nodeJS exists
#!/usr/local/bin node

console.log("Changing config");

var fs = require('fs');
var path = require('path');

var rootdir = process.argv[2];

//and so on
Run Code Online (Sandbox Code Playgroud)

当我现在构建应用程序时,我收到此错误:

pc295786:master kellster $ cordova build ios运行命令:/Users/kellster/documents/apps/master/hooks/before_prepare/001_c.js/Users/kellster/documents/apps/master错误: 在exports._errnoException(util.)生成EACCES. js:746:11)在Object.exports.spawn的Object.exports.spawn(child_process.js:988:9)的ChildProcess.spawn(child_process.js:1155:11)处(/ usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:104:31)at runScriptViaChildProcessSpawn(/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:188: 23)在/ usr/local/lib/node_modules/cordova/node_modules/cordova-的runScript(/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:131:16) lib/src/hooks/HooksRunner.js:114:20在_fulfilled(/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)的self.promiseDispatch.done(/ usr/local) /lib/node_modules/cordova/node_modules/q/q.js:816:30)在Promise.promise.promiseDispatch(/ usr/local)/lib/node_modules/cordova/node_modules/q/q.js:749:13)

要进行故障排除,我更改了钩子脚本的第一行

#!/usr/local/bin node
Run Code Online (Sandbox Code Playgroud)

至

#! node
Run Code Online (Sandbox Code Playgroud)

(因为这适用于Windows.node在全球范围内).但是,这导致了一个ENOENT错误:

pc295786:master kellster $ cordova build ios运行命令:/Users/kellster/documents/apps/master/hooks/before_prepare/001_c.js/Users/kellster/documents/apps/master错误:Hook失败,错误代码为ENOENT:/ Users /krster/documents/apps/master/hooks/before_prepare/001_c.js atus //rocal/lode/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:194:23在/rer /local/lib/node_modules/cordova/node_modules/q/q.js:797:24)在Promise.when的/usr/local/lib/node_modules/cordova/node_modules/q/q.js:823:30(/ usr/local/lib/node_modules/cordova/node_modules/q/q.js:1035:31)在Promise.promise.promiseDispatch(/usr/local/lib/node_modules/cordova/node_modules/q/q.js:741: 41)在/usr/local/lib/node_modules/cordova/node_modules/q/q.js:557:44在flush(/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17 )在启动时在Function.Module.runMain(module.js:503:11)的process._tickCallback(node.js:355:11)处(node.js:129:16)

如何构建这个?我很感激我能尝试的任何建议.


有些事情需要注意:

  1. (在我的绝望中,)我尝试运行以下命令,因为"EACCES"类型的错误.但是他们似乎都没有对结果产生任何影响.构建仍然失败.
sudo chmod 777 “/Users/kellster/documents/apps/master"
sudo chmod 777 “/usr/local/lib”
sudo chmod 777 "/usr/local/bin/"
chmod 777 "/Users/kellster/documents/apps/master/platforms/"
sudo chmod a+rwx "/Users/kellster/Documents/apps/Master/hooks/before_prepare/001_c.js"
sudo chmod a+rwx "/Users/kellster/Documents/apps/Master/"
sudo chown -R kellster /usr/local/lib/node_modules/cordova
Run Code Online (Sandbox Code Playgroud)

2)安装节点

在/ usr/local/bin目录

use*_*236 11

老答案:#!/ usr/local/bin node - >更好#!/ usr/bin/env节点

更新的答案:不要使用空格来引用节点可执行文件而是使用:

     #!/usr/local/bin/node 
Run Code Online (Sandbox Code Playgroud)

还要chmod你的脚本:例如:

      chmod 777 hooks/before_prepare/onde.js 
Run Code Online (Sandbox Code Playgroud)

其中onde.js是你的脚本.如果您使用的是Mac(我的情况)或Linux,那么您的.js必须在chmod 777上以避免EACCES错误.