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.
ℹ️ 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:
- retain use of gulp 3.9 (no need to migrate to gulp 4)
- use latest gulp-sass "^5.0.0" together with node-sass "^6.0.1"
- use the latest version of graceful-fs "^4.2.8"
- upgrading browsersync to "^2.27.5" resolves lots of weird things
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. |
- .npmrc >
engine-strict=true
- .nvmrc >
16
package.json
{
"engines": {
"npm": "please-use-yarn",
"yarn": ">= 1.22",
"node": ">= 16"
}
}
Make sure to clean your project directory before settings up npm or yarn.
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