如何使用nodejs构建跨平台项目?
我是在Windows上开发的,但是我的代码库构建在基于Linux的CI服务器上.它使用Grunt构建前端,并为此需要几个nodejs模块。
Nodejs要求将模块安装到项目的本地,以便由grunt.task.loadNpmTasks加载模块。问题是,我必须在某个地方安装它们,无论是Windows还是Linux,当我从一个安装时,它在另一个上就不能工作了。
我的项目所需的列表模块在本地安装,如下所示:
npm install connect-livereload --production
npm install time-grunt --production
npm install load-grunt-tasks --production
npm install jshint-stylish --production
npm install load-grunt-tasks --production
npm install grunt-contrib-copy --production
npm install grunt-contrib-concat --production
npm install grunt-contrib-uglify --production
npm install grunt-contrib-compass --production
npm install grunt-contrib-jshint --production
npm install grunt-contrib-cssmin --production
npm install grunt-contrib-connect --production
npm install grunt-contrib-clean --production
npm install grunt-contrib-htmlmin --production
npm install grunt-contrib-imagemin --production
npm install grunt-contrib-watch --production
npm install grunt-rev --production
npm install grunt-usemin --production
npm install grunt-mocha --production
npm install grunt-exec --production
npm install grunt-open --production
npm install grunt-svgmin --production
npm install grunt-concurrent --production
npm install grunt-ember-templates --production
npm install grunt-replace --production
npm install grunt-neuter --production如果我从Windows安装它,然后从Windows在项目文件夹上运行grunt,那么所有这些操作都是完美的。如果我然后将代码签入git并在linux框中构建,则chmod 777和chown对我的用户,并运行相同的grunt命令。它失败了,出现了很多这样的错误:
Running "mocha:all" (mocha) task
Testing: http://localhost:9000/index.html
Fatal error: spawn ENOENT我运行了npm install,它开始失败,带来了另一条消息:
Running "mocha:all" (mocha) task
Testing: http://localhost:9000/index.html
/home/administrator/platform/frontend/node_modules/grunt-contrib-compass/node_modules/tmp/lib/tmp.js:261
throw err;
^
Error: spawn ENOENT
at errnoException (child_process.js:998:11)
at Process.ChildProcess._handle.onexit (child_process.js:789:34)我所做的一切都不管用。
因此,在Linux中,我从我的项目中删除了整个node_modules目录,并重新运行上面的安装命令。现在,所有这些都可以在Linux上完美地工作。
然后,我将其签入git并在Windows中结帐。然后我转到项目文件夹并运行grunt,然后它失败了:
Running "mocha:all" (mocha) task
Testing: http://localhost:9000/index.html
Running PhantomJS...ERROR
>> 'c:\Users\Edy' is not recognized as an internal or external command,
0 [ '\'c:\\Users\\Edy\' is not recognized as an internal or external command,\r',
>> 'operable program or batch file.' ]
>> operable program or batch file. 1 [ '\'c:\\Users\\Edy\' is not recognized as an internal or external command,\r',
>> 'operable program or batch file.' ]
Warning: PhantomJS exited unexpectedly with exit code 1. Use --force to continue.卸载幻影并在本地安装无助于此。全球安装也于事无补。因此,让它在Windows上工作的唯一方法似乎是删除node_modules dir并在Windows上重新安装,这就引出了Linux上的第一个问题。
有没有一种方法可以在像我这样的跨平台环境中使用nodejs?我不敢相信我是第一个有这样的圈套的人
在这方面的任何提示或帮助都将受到赞赏。谢谢!
发布于 2014-06-22 03:46:19
node.js中的许多依赖项使用本机加载项。本机加载项是在npm install时为特定环境编译的。
如果您在不同环境之间移动,可以使用npm rebuild为新环境重新构建这些二进制文件。或者用更长的方式,再次删除node_modules文件夹和npm install。
Fatal error: spawn ENOENT意味着node.js试图生成的进程不存在。在试图为另一个环境生成编译的二进制文件时,它所期望的二进制文件是不存在的。
https://stackoverflow.com/questions/24347911
复制相似问题