Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run npm and bash from maven

Tags:

npm

maven

I have installed nodejs (npm) and npm install grunt-cli on my ubuntu box. I have found the nice maven-ant-run configuration for maven:

https://gist.github.com/nadavdav/5308453

but when I run mvn clean install from command-line I get:

building:
     [echo] ---------------------------------------------------
     [echo] -- NPM INSTALL --
     [echo] ---------------------------------------------------
     [exec] /usr/bin/npm: npm: line 2: syntax error near unexpected token `;'
     [exec] /usr/bin/npm: npm: line 2: `;(function () { // wrapper in case we're in module_context mode'

Why does npm fail when running inside maven?

EDIT: I have now updated the config to:

<!-- <exec executable="bash" dir="${project.basedir}" osfamily="unix" -->
<!--    failonerror="true"> -->
<!--    <arg line="npm install" /> -->
<!-- </exec> -->

<!-- WORKING -->
     <exec executable="npm" dir="${project.basedir}" failonerror="true">
    <arg value="install" />
     </exec>

which works. But strange that it does not work when running the original version.

like image 473
u123 Avatar asked Aug 16 '13 13:08

u123


1 Answers

Because in the first example, you were running 'bash' with the argument 'npm install', which is the same as running bash npm install on the commandline. This tells bash to try to run 'npm' as a shell script, but the npm script in your path is javascript code. Try it:

john-warden-mba-2012:nodetest john$ bash npm install
/opt/local/bin/npm: npm: line 2: syntax error near unexpected token `;'
/opt/local/bin/npm: npm: line 2: `;(function () { // wrapper in case we're in module_context mode'
like image 131
Jonathan Warden Avatar answered Nov 02 '22 06:11

Jonathan Warden