在Windows上开发并构build在Linux上的代码上使用NodeJs的Grunt?

如何使用nodejs构build跨平台项目?

我在Windows上开发,但是我的代码库build立在一个基于Linux的CI服务器上。 它使用Grunt构build前端,并且需要几个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中build立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上完美运行。

然后我检查到混帐和在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. 

卸载phantomjs并在本地安装不起作用。 全球安装也无济于事。 所以使它在Windows上工作的唯一方法似乎是删除node_modules目录并在Windows上重新安装,这使我在Linux上的第一个问题。

在像我这样的跨平台环境中有没有办法使用nodejs的东西? 我不敢相信我是第一个有这样的设置在那里嘿嘿

任何提示或帮助,在此表示赞赏。 谢谢!

node.js中的许多依赖项使用本地插件。 当您npm install时,将为您的特定环境编译本机插件。

如果您正在环境之间移动,您可以使用npm rebuild来为新环境重build这些二进制文件。 或者更长的方法,删除node_modules文件夹和npm install再次npm install

Fatal error: spawn ENOENT意味着一个进程node.js正在尝试产生不存在。 当试图产生一个二进制编译为另一个环境的常见情况下,它所期望的二进制文件不存在。