title: Dockerize ESLint with presets
body: <p>I'm trying to create a GitLab CI/CD stage that would only lint my code and run before all other steps. The trouble is that I'm trying to have the linting (together with its configuration) on a pre-built image for speed optimization reasons.</p>
  
  <p>My <code>.gitlab-ci.yml</code></p>
  
  <pre><code>stages:
    - prelint
    - lint
    - build
    - deploy
  
  build-linter:
    stage: prelint
    script: echo 'This builds the linter image'
    only:
      changes:
        - Dockerfile.lint
  
  lint:
    stage: lint
    image: prebuilt-linter
    script:
      - npm run lint
  </code></pre>
  
  <p>And the contents of <code>Dockerfile.lint</code>:</p>
  
  <pre><code>FROM node:lts-alpine
  
  RUN npm i -g eslint \
    prettier \
    @babel/core \
    core-js \
    core-js-compat@3.4.7 \
    eslint-config-prettier \
    eslint-plugin-prettier \
    eslint-plugin-vue \
    @vue/cli-service \
    @vue/cli-plugin-eslint \
    @vue/cli-plugin-babel \
    @vue/cli-plugin-unit-jest \
    @vue/cli-plugin-e2e-nightwatch \
    @vue/eslint-config-prettier \
    babel-eslint
  
  WORKDIR /app
  CMD eslint
  </code></pre>
  
  <p>However, it currently errors out because I think it's trying to find the dependencies from the project's own <code>node_modules/</code> directory and won't use the globally installed ones.</p>
  
  <pre><code>$ npm run lint
  00:01
  &gt; @project/1.0.0 lint /builds/frontend
  &gt; vue-cli-service lint
   ERROR  Error: Cannot find module '@vue/cli-plugin-babel/preset' from '/builds/frontend'
  Error: Cannot find module '@vue/cli-plugin-babel/preset' from '/builds/frontend'
      at Function.resolveSync [as sync] (/usr/local/lib/node_modules/@babel/core/node_modules/resolve/lib/sync.js:81:15)
      at resolveStandardizedName (/usr/local/lib/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
      at resolvePreset (/usr/local/lib/node_modules/@babel/core/lib/config/files/plugins.js:58:10)
      at loadPreset (/usr/local/lib/node_modules/@babel/core/lib/config/files/plugins.js:77:20)
      at createDescriptor (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
      at /usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
      at Array.map (&lt;anonymous&gt;)
      at createDescriptors (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
      at createPresetDescriptors (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
      at presets (/usr/local/lib/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! @project@1.0.0 lint: `vue-cli-service lint`
  npm ERR! Exit status 1
  npm ERR! 
  npm ERR! Failed at the @project@1.0.0 lint script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  npm WARN Local package.json exists, but node_modules missing, did you mean to install?
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-04-14T18_59_23_427Z-debug.log
  ERROR: Job failed: command terminated with exit code 1
  </code></pre>
  
  <p>What would be the best approach to have the dependencies necessary to make <code>eslint</code> work available in the built image, without having to install the dependencies each time? I wouldn't want to rely on installing the <code>devDependencies</code> of the project since there'd still be cache busts quite often because of irrelevant dependencies getting patched etc.</p>