title: How to solve Error: spawn EACCES on Jenkins when running Karma?
body: <p>I have setup an AWS Codepipeline.</p>
  
  <p>The pipeline uses Git as a source, Jenkins for testing and an EC2 instance for deployment.</p>
  
  <p>The project is based on <a href="https://github.com/AngularClass/angular-starter" rel="nofollow noreferrer">Angular Starter by Angular Class</a>. Thus, it uses Karma for unit testing.</p>
  
  <p>The Jenkins service runs on Ubuntu 16.04.</p>
  
  <p>Karma uses Headless Chrome for testing.</p>
  
  <p>The problem is that I currently get the folloing error when running the tests on Jenkins:</p>
  
  <pre><code>[31m07 05 2017 14:30:35.779:ERROR [karma]: [39m{ Error: spawn EACCES
      at exports._errnoException (util.js:1050:11)
      at ChildProcess.spawn (internal/child_process.js:319:11)
      at exports.spawn (child_process.js:378:9)
      at spawnWithoutOutput (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:168:24)
      at Object.ProcessLauncher._execCommand (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:76:21)
      at Object.ProcessLauncher._start (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:33:10)
      at Object.&lt;anonymous&gt; (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:19:10)
      at emitOne (events.js:101:20)
      at Object.emit (events.js:191:7)
      at Object.BaseLauncher.start (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/base.js:42:10)
      at Object.j (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launcher.js:116:17)
      at Object.setTimeout.bind.j (/var/lib/jenkins/workspace/ExampleTask/node_modules/qjobs/qjobs.js:143:18)
      at ontimeout (timers.js:386:14)
      at tryOnTimeout (timers.js:250:5)
      at Timer.listOnTimeout (timers.js:214:5) code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }
  </code></pre>
  
  <p>I have already done some research with the following findings:</p>
  
  <ul>
  <li>other people also had similar errors but related to to other packages</li>
  <li>the error may be related to wrong permissions</li>
  </ul>
  
  <p>What I have tried so far:</p>
  
  <ul>
  <li>checking the permissions of /var/lib/jenkins/workspace/ExampleTask ->
  result: owner is jenkins user</li>
  <li>give jenkins user root privileges (I know it is dangerous but I just wanted to try if it would work) -> result: error still exists</li>
  <li>allow jenkins user to run scripts with sudo -> result: nvm, npm and node is not defined; I tried to install nvm, npm and node manually but got a new error <code>permission denied /root/.nvm</code></li>
  </ul>
  
  <p>npm log file output looks as follows:</p>
  
  <pre><code>0 info it worked if it ends with ok
  1 verbose cli [ '/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/node',
  1 verbose cli   '/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/npm',
  1 verbose cli   'run',
  1 verbose cli   'test' ]
  2 info using npm@4.2.0
  3 info using node@v7.10.0
  4 verbose run-script [ 'pretest', 'test', 'posttest' ]
  5 info lifecycle  example@0.0.1~pretest:  example@0.0.1
  6 silly lifecycle  example@0.0.1~pretest: no script for pretest, continuing
  7 info lifecycle  example@0.0.1~test:  example@0.0.1
  8 verbose lifecycle  example@0.0.1~test: unsafe-perm in lifecycle true
  9 verbose lifecycle  example@0.0.1~test: PATH: /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/bin/node-gyp-bin:/var/lib/jenkins/workspace/ExampleTask/node_modules/.bin:/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/bin/node-gyp-bin:/var/lib/jenkins/workspace/ExampleTask/node_modules/.bin:/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
  10 verbose lifecycle  example@0.0.1~test: CWD: /var/lib/jenkins/workspace/ExampleTask
  11 silly lifecycle  example@0.0.1~test: Args: [ '-c', 'npm run lint &amp;&amp; karma start' ]
  12 silly lifecycle  example@0.0.1~test: Returned: code: 1  signal: null
  13 info lifecycle  example@0.0.1~test: Failed to exec test script
  14 verbose stack Error:  example@0.0.1 test: `npm run lint &amp;&amp; karma start`
  14 verbose stack Exit status 1
  14 verbose stack     at EventEmitter.&lt;anonymous&gt; (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
  14 verbose stack     at emitTwo (events.js:106:13)
  14 verbose stack     at EventEmitter.emit (events.js:194:7)
  14 verbose stack     at ChildProcess.&lt;anonymous&gt; (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/lib/utils/spawn.js:40:14)
  14 verbose stack     at emitTwo (events.js:106:13)
  14 verbose stack     at ChildProcess.emit (events.js:194:7)
  14 verbose stack     at maybeClose (internal/child_process.js:899:16)
  14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
  15 verbose pkgid  example@0.0.1
  16 verbose cwd /var/lib/jenkins/workspace/ExampleTask
  17 error Linux 4.4.0-1016-aws
  18 error argv "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/node" "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/npm" "run" "test"
  19 error node v7.10.0
  20 error npm  v4.2.0
  21 error code ELIFECYCLE
  22 error errno 1
  23 error  example@0.0.1 test: `npm run lint &amp;&amp; karma start`
  23 error Exit status 1
  24 error Failed at the  example@0.0.1 test script 'npm run lint &amp;&amp; karma start'.
  24 error Make sure you have the latest version of node.js and npm installed.
  24 error If you do, this is most likely a problem with the  example package,
  24 error not with npm itself.
  24 error Tell the author that this fails on your system:
  24 error     npm run lint &amp;&amp; karma start
  24 error You can get information on how to open an issue for this project with:
  24 error     npm bugs  example
  24 error Or if that isn't available, you can get their info via:
  24 error     npm owner ls  example
  24 error There is likely additional logging output above.
  25 verbose exit [ 1, true ]
  </code></pre>