How to fix error “cannot find module gulp-sass” in Gulp
When you’re running Gulp, you might see an error that says something like “cannot find module gulp-sass”.
This error message means that Gulp is trying to run a function from the gulp-sass package, but it can’t locate it.
If you’re getting this annoying error, here are a few fixes that you can use to get rid of it.
Check your node_modules folder
When you install npm packages, npm will create a
node_modules folder in your project root. It will also add packages you’ve installed to your
You can confirm that a package has been installed by making sure it’s listed in your
package-lock.json files. And double-check your
node_modules folder to make sure the package is in a subfolder there.
Lastly, make sure you are running your website or web app from the project root folder, and that the root folder contains the
node_modules folder as a direct subfolder. If the
node_modules folder isn’t in that location, it may cause this error.
Install the gulp-sass module manually
If you don’t see the
gulp-sass package in your
node_modules folder, or are still having issues, you can try reinstalling the package.
First, open your
package-lock.json files and remove any references to
node-sass that you see. This will make sure that you will reinstall the most up-to-date version of the packages.
npm install gulp-sass or
npm install gulp-sass --save-dev to install and save in
package.json file. Adding the
--save-dev flag will add packages to the
devDependencies section of your
If you don’t add the flag it will get added to the
dependencies section of the file. Especially if you’re just working locally, it doesn’t matter a ton which section you use, so follow your own preferences on this.
Note that this will install the package locally in your project folder, and the package will be accessible only from that project. You can also install packages globally on your computer, so that they are accessible from any other directory.
You can do this by adding the global (
-g) flag to the
install command, like this:
npm install -g gulp-sass.
However I usually install packages local to the project. I do install the
gulp-cli globally, but everything else I just keep local.
Delete and reinstall all npm packages
If just removing and reinstalling just the
gulp-sass package doesn’t work, you can try deleting and reinstalling all your npm packages.
First, make sure that all the packages you need in your project exist in your
package.json file. Also make sure that
gulp-sass exists in your
Then, delete your
node_modules folder. You can do this by deleting from your file explorer, or running
rm node_modules in the command line. If you encounter errors or difficulties deleting the folder, you can try installing an npm package called rimraf that helps with deleting.
I install rimraf globally on my computer so I can run it from any directory. You can install rimraf globally by running
npm install -g rimraf. Then you can attempt to delete the folder by running
rimraf node_modules from the project root command line.
If you still have issues or get an error like
node_modules\@types is not accessible you may need to first close VS Code or whichever code editor you are using. Then try deleting the folder again.
Once you have successfully deleted the
node_modules folder, run
npm install from your project root to install all the packages you have listed.
I'm making a course that will teach you how to build a real-world responsive website from scratch!Learn more