NPM can't find local installed modules in Jenkins pipeline project
<p>I'm trying to build a angular2 project on Jenkins using a Jenkinsfile. The project is generated using angular-cli. I wasn't able to run the locally installed modules through a script. In my case <code>typings</code> can't be found when the postinstall script, <code>typings install</code>, is called when running <code>npm install</code>.</p>

<p>When I build the project locally, on Windows, everything works fine. But running the commands in a Jenkins on Linux I get the issue as described above.</p>

<p>I've solved it for now by adding <code>./node_modules/.bin</code> to the PATH in the Jenkinsfile, but I was expecting that the locally installed modules would automatically be added to the path when using <code>npm</code>: <a href="https://docs.npmjs.com/files/folders#executables" rel="nofollow">https://docs.npmjs.com/files/folders#executables</a>.</p>

<p>(I know I should use the result from <code>npm bin</code> instead of using <code>./node_modules/.bin</code>)</p>

<p>My question is: Didn't I understand the documentation correctly and do I really need to manually add the local bin directory to the PATH? And how do I fix my setup so I don't need to do that (without using globally installed packages)? Or what is the best way to add <code>npm bin</code> to the PATH?</p>

<p>package.json:</p>

<pre><code>{
  "name": "hello",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "postinstall": "typings install",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test --watch=false",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.2",
    "es6-shim": "0.35.1",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.26",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.10",
    "codelyzer": "0.0.20",
    "ember-cli-inject-live-reload": "1.4.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "karma-junit-reporter": "1.1.0",
    "protractor": "3.3.0",
    "ts-node": "0.5.5",
    "tslint": "3.11.0",
    "typescript": "1.8.10",
    "typings": "1.3.1"
  }
}
</code></pre>

<p>Jenkinsfile (snippet):</p>

<pre><code>node {

  withNodeEnv {
      sh "npm install"
      sh "ng test"
  }

}

void withNodeEnv(Closure body) {
    String nodeTool = tool name: 'node4LTS', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'

    // Create environment with NodeJS added to the PATH.
    List nodeEnv = ["PATH+NODE=${nodeTool}/bin", "PATH+NODE_MODULES=./node_modules/.bin"]

    // Invoke the body closure within in the environment with NodeJS added.
    withEnv(nodeEnv) {
        body.call()
    }
}
</code></pre>

<p>I'm using:</p>

<ul>
<li>Jenkins:2.10 (w/ NodeJS plugin v0.2.1)</li>
<li>node:4.4.7 (without globally installed packages)</li>
<li>angular-cli:1.0.0-beta.10</li>
</ul>