Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run build and tests in production environment when devDependencies don't get installed?

I'm sure this is a common issue but I can't seem to find a definitive answer.

I have a node application which in order to build requires some devDependencies such as babel. In order to run my tests also requires devDependencies such as jest. But when CI runs in production environment, it obviously doesn't install any devDependencies so I get errors where the package isn't found.

What is the best practice for running builds and tests in prod without devDependencies?

If it helps, I am running my build in GitLab Pipelines:

image: node:8.11.2

stages:
  - prepare
  - test
  - deploy

install_and_build:
  stage: prepare
  script:
    - npm install yarn
    - yarn
    - yarn build
  only:
    - master

test:
  stage: test
  script:
    - yarn test
  only:
    - master

deploy_production:
  type: deploy
  stage: deploy
  image: ruby:latest
  script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=app-name --api-key=$HEROKU_API_KEY
  only:
    - master
like image 391
Stretch0 Avatar asked Oct 18 '25 05:10

Stretch0


1 Answers

From this answer,

First, you need to "install with all dependencies".

npm install

Then do your tests.

npm test

Then "prune" your dev dependencies as below, as detailed in the docs doing this "will remove the packages specified in your devDependencies".

npm prune --production
like image 127
Leponzo Avatar answered Oct 20 '25 19:10

Leponzo