The long way through Software Craftsmanship

Convert a project from npm to yarn

Mar 3, 2017 - 1 minute read - Comments - dockertoolpipelinejenkinsyarnnpmjavascript

At a client, we’re converting all projects (i.e., sites, services, libraries) from npm to yarn. Mostly for the speed (as it uses the internal cache).

Step by step guide

  1. Install yarn in your local environment * https://yarnpkg.com/lang/en/docs/install/
  2. Run yarn install * This will create a yarn.lock file * Add that file to the repo: git add yarn.lock
  3. Modify Dockerfile * Install yarn (in the Dockerfile). Idea: shortcut this execution with yarn --version in case it is installed * Configure the PATH variable (ENV PATH …) * ADD yarn.lock * Replace npm install with yarn install
  4. Modify pipeline * See example (below) * install_yarn. Idea: shortcut this execution with yarn --version in case it is installed * Replace npm install with yarn install
  5. Test it

Jenkins

Build step: execute shell

function install_yarn {
  yarn --version || curl -o- -L https://yarnpkg.com/install.sh | bash
  export PATH="$HOME/.yarn/bin:$PATH"
}

install_yarn

yarn install

Disclaimer about AI/GenAI

As of 2026-05-06, the text in these articles and blog entries has been written without AI/GenAI, except I sometimes use a spellchecker to fix errors. Think Word's spellchecker, not ChatGPT.

Notes, as of today (2026-05-06):

  • No code snippet has been automatically generated, nor vibe-coded, nor generated and reviewed.
  • I don’t have any article with AI contribution.

For future entries:

  • I may have used GenAI for the code in the repo. The code I exemplify/copy in the article will always be reviewed and tested, not vibe-coded. I will specify it in each snippet or at the top/bottom of the article.
  • I normally don't use it for the text contents, although if I have used it for the article text, it would be indicated as such.

Any entry before 2026-05-06 does not contain any AI/GenAI.

For more information, read the AI/GenAI Policy

Self-Study in March 2017 Modifying titles in a Trello Board