title: Bitbucket Pipelines from Docker Image has Missing NPM Modules
body: <h2>Question</h2>
  
  <p>What is wrong with my <code>Dockerfile</code> or <code>bitbucket-pipelines.yml</code>? Why are modules missing from the bitbucket pipelines environment?</p>
  
  <h2>Error</h2>
  
  <p>When I try to <code>npm run build</code> my Vue2 project with webpack using Bitbucket Pipelines, I get errors regarding missing modules.</p>
  
  <p><em>From Logs</em></p>
  
  <pre><code>npm run build
  &gt; people-is@1.0.0 build /opt/atlassian/pipelines/agent/build
  &gt; node build/build.js
  module.js:549
      throw err;
      ^
  Error: Cannot find module 'cli-spinners'
  </code></pre>
  
  <h2>Files</h2>
  
  <p>Here are the files for configuration.</p>
  
  <p><strong>Dockerfile</strong> - <em>builds cportwine/people-is</em></p>
  
  <pre><code>FROM node:8.10.0
  
  RUN npm install
  RUN npm install -g firebase-tools
  
  CMD [ "npm", "run", "build" ]
  </code></pre>
  
  <p><strong>bitbucket-pipelines.yml</strong></p>
  
  <pre><code>image:
    name: cportwine/people-is
  pipelines:
    default:
      - step:
          script:
            - npm run build
  </code></pre>
  
  <p><strong>package.json</strong></p>
  
  <pre><code>{
    "name": "people-is",
    "version": "1.0.0",
    "description": "A Vue.js project",
    "author": "cportwine",
    "private": true,
    "scripts": {
      "dev": "node build/dev-server.js",
      "start": "node build/dev-server.js",
      "build": "node build/build.js",
      "deploy": "firebase deploy --token $FIREBASE_TOKEN"
    },
    "dependencies": {
      "rxjs": "^5.5.8",
      "uuid": "^3.2.1",
      "vue": "^2.5.16",
      "vue-json-excel": "^0.1.9",
      "vue-router": "^2.8.1",
      "vue-rx": "^5.0.0",
      "vuefire": "^1.4.5",
      "vuetify": "^0.15.2"
    },
    "devDependencies": {
      "autoprefixer": "^7.2.6",
      "babel-core": "^6.22.1",
      "babel-loader": "^7.1.4",
      "babel-plugin-transform-runtime": "^6.22.0",
      "babel-preset-env": "^1.6.1",
      "babel-preset-stage-2": "^6.22.0",
      "babel-register": "^6.22.0",
      "chalk": "^2.3.2",
      "connect-history-api-fallback": "^1.5.0",
      "copy-webpack-plugin": "^4.5.1",
      "css-loader": "^0.28.11",
      "cssnano": "^3.10.0",
      "eslint": "^4.19.1",
      "eslint-config-standard": "^11.0.0",
      "eslint-friendly-formatter": "^3.0.0",
      "eslint-loader": "^1.9.0",
      "eslint-plugin-html": "^4.0.2",
      "eslint-plugin-promise": "^3.7.0",
      "eslint-plugin-standard": "^3.0.1",
      "eventsource-polyfill": "^0.9.6",
      "express": "^4.16.3",
      "extract-text-webpack-plugin": "^2.0.0",
      "file-loader": "^0.11.1",
      "firebase": "^4.12.0",
      "firebase-tools": "^3.17.7",
      "friendly-errors-webpack-plugin": "^1.1.3",
      "html-webpack-plugin": "^2.28.0",
      "http-proxy-middleware": "^0.17.3",
      "opn": "^5.3.0",
      "optimize-css-assets-webpack-plugin": "^2.0.0",
      "ora": "^1.4.0",
      "rimraf": "^2.6.0",
      "semver": "^5.5.0",
      "shelljs": "^0.7.6",
      "url-loader": "^0.5.8",
      "vue-loader": "^13.7.1",
      "vue-style-loader": "^3.1.2",
      "vue-template-compiler": "^2.5.16",
      "vuex": "^2.5.0",
      "webpack": "^2.6.1",
      "webpack-bundle-analyzer": "^2.11.1",
      "webpack-dev-middleware": "^1.12.2",
      "webpack-hot-middleware": "^2.21.2",
      "webpack-merge": "^4.1.2"
    },
    "engines": {
      "node": "&gt;=8.10.0",
      "npm": "&gt;= 5.6.0"
    },
    "browserslist": [
      "&gt; 1%",
      "last 2 versions",
      "not ie &lt;= 8"
    ],
    "main": "index.js",
    "repository": {
      "type": "git",
      "url": "git+https://chaddportwine@bitbucket.org/jahnelgroup/people-is.git"
    },
    "keywords": [],
    "license": "ISC",
    "homepage": "https://bitbucket.org/jahnelgroup/people-is#readme"
  }
  </code></pre>
  
  <h2>What I see</h2>
  
  <p>When I <code>ls</code> the <code>node_modules</code> folder in both environments, they do not match. Modules are missing from bitbucket pipelines.</p>
  
  <p><strong>local folder</strong></p>
  
  <p><code>people-is/node_modules</code></p>
  
  <pre><code>...
  chalk
  char-spinner
  chardet
  check-types
  chokidar
  chownr
  cipher-base
  circular-json
  cjson
  clap
  class-utils
  clean-css
  cli-boxes
  cli-cursor
  cli-spinners
  cli-table
  cli-table2
  cli-width
  cliui
  ...
  </code></pre>
  
  <p><strong>bitbucket folder</strong></p>
  
  <p><code>/opt/atlassian/pipelines/agent/build/node_modules</code></p>
  
  <p><strong>Woah, missing modules!</strong></p>
  
  <pre><code>...
  chalk
  cli-cursor
  co
  ...
  </code></pre>
  
  <h2>What I have tried</h2>
  
  <p>I added a command to the <code>bitbucket-pipelines.yml</code> to <code>npm install</code> before I build.</p>
  
  <p><strong>bitbucket-pipelines.yml</strong></p>
  
  <pre><code>image:
    name: cportwine/people-is
  pipelines:
    default:
      - step:
          script:
            - npm install
            - npm run build
  </code></pre>
  
  <p>This adds some additional modules (like <code>cli-spinners</code> from the error) to <code>/opt/atlassian/pipelines/agent/build/node_modules</code>.</p>
  
  <p><strong>bitbucket folder</strong></p>
  
  <p><code>/opt/atlassian/pipelines/agent/build/node_modules</code></p>
  
  <pre><code>...
  chalk
  char-spinner
  chardet
  check-types
  chokidar
  chownr
  cipher-base
  circular-json
  cjson
  clap
  class-utils
  clean-css
  cli-boxes
  cli-cursor
  cli-spinners
  cli-table
  cli-table2
  cli-width
  cliui
  clone
  clone-response
  co
  ...
  </code></pre>
  
  <p>However, the build command still fails, due to a different missing module.</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>&gt; people-is@1.0.0 build /opt/atlassian/pipelines/agent/build
  &gt; node build/build.js
  module.js:549
      throw err;
      ^
  Error: Cannot find module './_safeGet'
  </code></pre>