Fix for node-sass build error in netlify build

You can also check other posts on npm command deprecate option is deprecated In this tutorial, learn how to fix an error for the installation of node-sass during the netlify build.

I got this error during node project deployment in netlify production

4:54:23 PM: npm WARN rm not removing /opt/build/repo/node_modules/.bin/gulp as it wasn't installed by /opt/build/repo/node_modules/gulp-cli
4:54:23 PM: > [email protected] install /opt/build/repo/node_modules/node-sass
4:54:23 PM: > node scripts/install.js
4:54:23 PM: Unable to save binary /opt/build/repo/node_modules/node-sass/vendor/linux-x64-57 : { Error: ENOENT: no such file or directory, mkdir '/opt/build/repo/node_modules/node-sass/vendor/linux-x64-57'
4:54:23 PM: at Object.fs.mkdirSync (fs.js:885:18)
4:54:23 PM: at checkAndDownloadBinary (/opt/build/repo/node_modules/node-sass/scripts/install.js:113:8)
4:54:23 PM: at Object.<anonymous> (/opt/build/repo/node_modules/node-sass/scripts/install.js:156:1)
4:54:23 PM: at Module.\_compile (module.js:653:30)
4:54:23 PM: at Object.Module.\_extensions..js (module.js:664:10)
4:54:23 PM: at Module.load (module.js:566:32)
4:54:23 PM: at tryModuleLoad (module.js:506:12)
4:54:23 PM: at Function.Module.\_load (module.js:498:3)
4:54:23 PM: at Function.Module.runMain (module.js:694:10)
4:54:23 PM: at startup (bootstrap_node.js:204:16)
4:54:23 PM: errno: -2,
4:54:23 PM: code: 'ENOENT',
4:54:23 PM: syscall: 'mkdir',
4:54:23 PM: path: '/opt/build/repo/node_modules/node-sass/vendor/linux-x64-57' }

node-sass is a node package for sass compilation which requires building native tools and binaries required for each environment.

This is going to be deprecated and will not be used in the future.

What is the alternative for the node-sass library?

sass-loader is a package for loads and compiling sass/scss files into CSS.

First, uninstall node-sass from your project

npm uninstall node-sass

Install sass and sass-loader into your project

npm install sass --save-dev
npm install node-sass --save-dev

If you want to continue using node-sass in netlify,

You have to use the correct version for node-sass with the node version

You can check the compatible node-sass version here🔗

And also you can change node version in netlify.

Conclusion

You learned how to solve the node-sass error in the netlify build.