Skip to content

Instantly share code, notes, and snippets.

@monnoval
Last active October 19, 2021 03:34
Show Gist options
  • Save monnoval/ab04caa6acbb7a23429f428c94815a6c to your computer and use it in GitHub Desktop.
Save monnoval/ab04caa6acbb7a23429f428c94815a6c to your computer and use it in GitHub Desktop.
Upgrading from Node v10 to latest

Node releases are fast and not-so-easy to keep up. And upgrading to the latest node version (16 as of Oct 2021) is not really that much of work. Maybe few minutes should be enough while very hopeful at upgrading the packages easily.


1. Quick intro

ℹ️ gulp 3.9 vs gulp 4
This post is mainly for projects using gulp 3.9.
If you are using gulp 4 then moving to latest node would be much easier and may not need to do any of the below.

In this post I mainly use gulp3.9 + yarn + node 16. Here's a quick summary:

  1. retain use of gulp 3.9 (no need to migrate to gulp 4)
  2. use latest gulp-sass "^5.0.0" together with node-sass "^6.0.1"
  3. use the latest version of graceful-fs "^4.2.8"
  4. upgrading browsersync to "^2.27.5" resolves lots of weird things

1.1 gulpfile & package.json

gulpfile.js

// var sass = require('gulp-sass')
var sass = require('gulp-sass')(require('node-sass'))

package.json

{
  "devDependencies": {
    "browser-sync": "^2.27.5",
    "gulp": "^3.9.1",
    "gulp-sass": "^5.0.0",
    "node-sass": "^6.0.1"
  },
  "resolutions": {
    "graceful-fs": "^4.2.8"
  }
}

graceful-fs use of version 4 is important only when using gulp 3.9

💡 Use major version (16) rather than minor+patch versions (16.11.1)
This is to broaden the build requirements rather than isolate it to specific version.
At the same time lessen the need to use specific versions for every project.

1.2 Lock and forget

  • .npmrc > engine-strict=true
  • .nvmrc > 16

package.json

{
  "engines": {
    "npm": "please-use-yarn",
    "yarn": ">= 1.22",
    "node": ">= 16"
  }
}

1.3 Setting up

Make sure to clean your project directory before settings up npm or yarn.

⚠️ Backup if you are doing a major upgrade
Do copy your node_modules folder somewhere before deleting it.
Sometimes it takes long time to re-download all this packages.
rm -rf node_modules  # delete the node_modules folder
rm package.lock      # delete package lock if exist
rm yarn.lock         # delete yarn lock if you are using yarn
nvm use              # for windows use this command > nvm use `cat .nvmrc`
yarn                 # setup yarn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment