Keep the same Node.js version between local environment and Github Actions
Emmanuel Gautier / October 30, 2022
2 min read
It can be complicated to have the same Node version between the local environment and the CI/CD. The latest Node.js version or the latest lts is released recently and if you want to upgrade to the Node version, usually you can forget to configure one environment. For that reason, it can be important to have only one source of truth to define the Node version, so you change in one place it impacts every environment.
Here we will use nvm and have the CI/CD example with Github Actions. Some other CI/CD solutions can exist elsewhere using a similar configuration and reproduce the common configuration.
First of all, you should configure a .nvmrc
file defining the version you want to use. This version will be used in your local environment. To use it, you can either make an nvm use
each time you go to the project's local directory or configure your bash to use it automatically.
Here is an example of a .nvmrc
file content:
lts/hydrogen
Then, you can configure the Github Action so to use the same .nvmrc file.
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup node env
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: 'yarn'
Now, when you change the .nvmrc file, it changes the version used for your local environment, the Node environment for all your team, and the CI/CD running on Github.
Comments
Related Posts
How to use Chakra UI Button and Link components with NextJS Link
There is some glue to add to make Chakra UI and NextJS work together. The Chakra UI components do not generate the "a" tag by default for a link. Let's see how to use the Chakra button to generate links between pages.
Publish on Cloudflare Pages with unsupported language versions
It may happen that a version of Node is not supported yet by Cloudflare and will remain not supported for some weeks. That can happen even if it is a Long Term Support (LTS) version. Here how to build even if cloudflare does not support the version.
Publish on Cloudflare Pages with unsupported language versions
It may happen that a version of Node is not supported yet by Cloudflare and will remain not supported for some weeks. That can happen even if it is a Long Term Support (LTS) version. Here how to build even if cloudflare does not support the version.
Featured Posts
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
How to enable Python type checking in VSCode
Python now has support for type hints. In this article, we will see how to enable better IntelliSense and type checking analysis in VSCode.
How to manage Internationalization with NextJS SSG
Staticaly generating a website with the NextJS framework in different languages is not so obvious.