node npm from maven looks npm-cli.js in project di

2020-07-22 16:33发布

I'm running 'npm install' from maven using exec-maven-plugin. And it fails with such error:

module.js:340
throw err;
      ^
Error: Cannot find module 'D:\projects\git\code\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

obviously there is no npm-cli under project path, it's in the global path where nodejs is installed.

So the whole build is failed with status

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm) on project myproject: Command execution failed. Process exited with an error: 8 (Exit value: 8) -> [Help 1]

Another interesting thing that 'npm install' under console is run perfectly fine. Problem only occurs when I run it from maven.

Any thoughts would be appreciated!

2条回答
我只想做你的唯一
2楼-- · 2020-07-22 16:43

Another workaround, in case anyone else is stuck on an older JDK like me, is to run

cmd /c npm install

from exec-maven-plugin.

查看更多
闹够了就滚
3楼-- · 2020-07-22 16:44

Its amazing how version of java can affect the behavior of maven.

The problem was in using java1.7_25,java when it tried to run exec task from maven it broke the ~dp0 path(the target path of the task which is run).

I simple updated to java1.7_40 and everything went perfectly fine.

查看更多
登录 后发表回答