NPM task failing
Asked by Matt Lupo:

I'm trying to set the Node JS capability in Bamboo 5.9.0 running on windows 2012 R2 server. I installed Node JS/NPM on the server directly, and Bamboo detected the capability. The build plan I'm currently running has a simple NPM task, and it's failing. Running it on a local agent. I have the Node JS 1.7.8 add on installed, but it does say it's incompatible. Yet the server detects the capability. Receiving the following error:

```
Error occurred while running Task 'Run CI Tests(2)' of type com.atlassian.bamboo.plugins.bamboo-nodejs-plugin:task.builder.npm.error	15-Aug-2017 20:48:28	com.atlassian.bamboo.task.TaskException: Failed to execute taskerror	15-Aug-2017 20:48:28		at com.atlassian.bamboo.plugins.nodejs.tasks.npm.NpmTaskType.execute(NpmTaskType.java:107)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.task.TaskExecutorImpl$3.call(TaskExecutorImpl.java:288)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.task.TaskExecutorImpl$3.call(TaskExecutorImpl.java:284)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.task.TaskExecutorImpl.executeTaskWithPrePostActions(TaskExecutorImpl.java:200)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.task.TaskExecutorImpl.executeTasks(TaskExecutorImpl.java:284)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.task.TaskExecutorImpl.execute(TaskExecutorImpl.java:106)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.build.pipeline.tasks.ExecuteBuildTask.call(ExecuteBuildTask.java:75)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent.build(DefaultBuildAgent.java:196)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl$1.call(BuildAgentControllerImpl.java:122)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl$1.call(BuildAgentControllerImpl.java:114)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:215)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.waitAndPerformBuild(BuildAgentControllerImpl.java:113)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent$1.run(DefaultBuildAgent.java:118)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:49)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:31)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:20)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:52)error	15-Aug-2017 20:48:28		at java.lang.Thread.run(Thread.java:745)error	15-Aug-2017 20:48:28	Caused by: java.lang.IllegalArgumentException: The working directory must exist before executing the processerror	15-Aug-2017 20:48:28		at org.apache.commons.lang.Validate.isTrue(Validate.java:136)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.process.ProcessServiceImpl.createExternalProcess(ProcessServiceImpl.java:166)error	15-Aug-2017 20:48:28		at com.atlassian.bamboo.process.ProcessServiceImpl.executeExternalProcess(ProcessServiceImpl.java:213)error	15-Aug-2017 20:48:28		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)error	15-Aug-2017 20:48:28		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)error	15-Aug-2017 20:48:28		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)error	15-Aug-2017 20:48:28		at java.lang.reflect.Method.invoke(Method.java:606)error	15-Aug-2017 20:48:28		at 
```


Answers:
author: Jeyanthan I
body: Looking at the error, the npm task is telling us that the directories does not exist.

```
Caused by: java.lang.IllegalArgumentException: The working directory must exist before executing the process
```

You may have to add a [script task](https://confluence.atlassian.com/bamboo/script-289277046.html) to create directories before running npm install task runs.

Also, are you able to run npm install via command line successfully?

That said, Bamboo 5.9 is quite outdated and you should consider upgrading to the latest version.  

comments: author: Matt Lupo
body: Thanks for the response. I ran 'npm install' in command prompt under the folder that has nodejs.exe. I've attached an image of what it displayed. It looks like it ran, but gave an unable to find package.json message, along with a few others![npminstall.png](https://community.atlassian.com/t5/image/serverpage/image-id/4784iA46567C79692A15A/image-size/large?v=v2&px=999 "npminstall.png")


author: Matt Lupo
body: I plan on upgrading from 5.9 soon, just verifying compatibility with what we're using bamboo for.


author: Matt Lupo
body: Ok, I was able to run npm install and the npm run testci command successfully from the command line itself. I can create a batch file that runs 'start cmd' and 'npm run testci' as a script task as well. It looks like it's doing everything it's supposed to in the log, but the build never finishes.

As for setting a specific npm task in bamboo, I still get the same error as I listed initially, even if I set the sub directory to the build directory containing package.json.


Tags: npm