The “can not find module sass” error indicates your project lacks the Sass compiler package. This common issue stops your CSS preprocessing dead in its tracks, but fixing it takes only a few minutes.
You might see this error when running a build script, starting a development server, or compiling styles with tools like Webpack, Vite, or Gulp. The message is straightforward: your Node.js project cannot locate the sass module.
Let’s break down why this happens and how to resolve it step by step.
What Causes The Can Not Find Module Sass Error
This error almost always means the sass npm package is not installed in your project. It could be missing from node_modules, not listed in package.json, or installed globally when it should be local.
Another common cause is a mismatch between the Sass version and your build tool. For example, older versions of Webpack require node-sass, while newer setups prefer the Dart-based sass package.
Sometimes the error appears after cloning a repository or switching branches. The node_modules folder might be outdated or incomplete.
Check Your Package Manager
First, verify which package manager you are using. npm, yarn, and pnpm all handle dependencies slightly differently.
- Run
npm list sassto see if the package is installed - Try
yarn list sassif you use Yarn - For pnpm, use
pnpm list sass
If the output shows (empty) or a missing version, the module is not installed.
Look At Your Package.Json File
Open your package.json and check both dependencies and devDependencies. The sass package should appear in one of these sections.
If it is missing, you need to install it. If it is present but the error persists, the installation might be corrupted.
How To Fix Can Not Find Module Sass
Here are the most reliable solutions, ordered from simplest to most thorough.
Install The Sass Package Locally
The quickest fix is to install the Sass compiler as a development dependency.
- Open your terminal in the project root directory
- Run
npm install sass --save-devfor npm - Or
yarn add sass --devfor Yarn - Or
pnpm add sass -Dfor pnpm
This adds the package to node_modules and updates package.json. After installation, try running your build command again.
Delete And Reinstall Node_Modules
Sometimes the installation gets corrupted. A clean reinstall often solves stubborn cases.
- Delete the
node_modulesfolder - Delete the
package-lock.jsonoryarn.lockfile - Run
npm install(or your package manager’s equivalent)
This forces a fresh download of all dependencies, including Sass.
Check For Global Installation Conflicts
If you previously installed Sass globally with npm install -g sass, your project might not find it. Local projects do not automatically use global modules.
Uninstall the global version to avoid confusion:
npm uninstall -g sass
Then install it locally as shown above.
Verify Your Build Tool Configuration
Different tools expect Sass in different ways. Check your configuration files.
For Webpack, look in webpack.config.js for the sass-loader rule. The loader requires the sass package to be installed.
For Vite, the vite.config.js file might need explicit Sass configuration. Vite usually detects Sass automatically, but a misconfigured project can cause errors.
For Gulp, check your gulpfile.js for the gulp-sass plugin. This plugin also needs the sass package.
Can Not Find Module Sass In Specific Environments
The error can appear in different contexts. Here is how to handle each one.
React And Create React App
If you use Create React App, Sass support is built in. You only need to install the sass package.
- Run
npm install sass - Rename your
.cssfiles to.scss - Import them normally in your components
No additional configuration is required.
Next.Js Projects
Next.js also supports Sass out of the box. Install the package and use .scss files.
- Run
npm install sass - Import your styles in pages or components
- Next.js handles the compilation automatically
If you use CSS modules with Sass, name your files *.module.scss.
Angular Projects
Angular uses Sass natively. The error usually means the CLI cannot find the compiler.
- Run
ng add @angular/materialif you use Material Design - Or install Sass manually with
npm install sass --save-dev - Check your
angular.jsonfor the styles configuration
Angular’s build process should pick up the installed package automatically.
Vue.Js Projects
Vue CLI projects require the sass package and the sass-loader for Webpack.
- Run
npm install sass sass-loader --save-dev - Use
<style lang="scss">in your Vue components - The loader compiles your styles during build
For Vite-based Vue projects, only sass is needed. Vite includes its own loader.
Preventing The Can Not Find Module Sass Error
Once you fix the error, take steps to avoid it in the future.
Always Use Local Dependencies
Never rely on global installations for project-specific tools. Always add Sass to your devDependencies.
This ensures that anyone cloning your repository can install all required packages with a single command.
Commit Your Lock File
Always commit package-lock.json or yarn.lock to version control. This locks the exact versions of your dependencies.
When other developers run npm install, they get the same versions you used. This prevents version mismatches.
Use A Consistent Node Version
Different Node.js versions can cause compatibility issues with Sass. Use a .nvmrc file or engines field in package.json to specify the Node version.
"engines": {
"node": ">=16.0.0"
}
This helps team members use the same runtime environment.
Run Install After Cloning
Always run npm install immediately after cloning a repository. Skipping this step is the most common cause of missing module errors.
Make it a habit before running any build commands.
Troubleshooting Persistent Can Not Find Module Sass Errors
Sometimes the standard fixes do not work. Here are advanced troubleshooting steps.
Check For Typing Errors In Import Statements
A typo in your import path can cause a similar error. Double-check that you are importing sass correctly.
- In JavaScript:
import sass from 'sass' - In CSS:
@import 'variables';(without the file extension) - In Webpack config:
require('sass')
Make sure the package name is spelled exactly as sass, not saas or scss.
Verify The Module Path
If you have a monorepo or custom module resolution, the package might be installed in a different location.
Run npm root to see where npm installs packages. Then check if sass exists in that directory.
For Yarn workspaces, ensure the package is hoisted to the root node_modules.
Clear The Npm Cache
A corrupted cache can cause installation issues. Clear it and reinstall.
npm cache clean --force
rm -rf node_modules
npm install
This removes any cached data that might be causing problems.
Use Node-Sass As A Fallback
If the Dart-based sass package continues to fail, try the older node-sass package.
- Run
npm uninstall sass - Run
npm install node-sass --save-dev - Update your build configuration to use
node-sass
Note that node-sass is deprecated but still works for many projects. It requires native compilation, which can cause its own set of errors.
Can Not Find Module Sass In Docker Containers
Docker environments add another layer of complexity. The error often occurs because the container does not have the package installed.
Ensure Dockerfile Installs Dependencies
Your Dockerfile should include a step to install npm packages.
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "build"]
Make sure the npm install command runs before your build command.
Use Multi-Stage Builds
For production images, use multi-stage builds to keep the final image small.
FROM node:18 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/build /usr/share/nginx/html
This ensures all build dependencies, including Sass, are available during the build phase.
Common Misconfigurations That Trigger The Error
Some project setups are more prone to this error. Here are patterns to avoid.
Missing DevDependencies
If you install Sass as a regular dependency instead of a dev dependency, it still works. But if you accidentally omit it from package.json entirely, the error appears.
Always double-check your package.json after installation.
Incorrect File Extensions
Sass files use .scss or .sass extensions. If you name a file .css but use Sass syntax, the compiler will not process it.
Rename your files to the correct extension and update your imports.
Conflicting Loader Versions
In Webpack, the sass-loader version must be compatible with the sass version. Check the documentation for your loader.
For example, sass-loader@12 works with sass@1.32 and later.
Frequently Asked Questions About Can Not Find Module Sass
What Does “Can Not Find Module Sass” Mean?
It means your Node.js project cannot locate the Sass compiler package. The package is either not installed, not in the correct location, or not listed in your dependencies.
Should I Use Sass Or Node-sass?
Use the Dart-based sass package for new projects. It is actively maintained and faster. Only use node-sass if you have legacy code that requires it.
Can I Install Sass Globally To Fix This Error?
No, global installations do not solve local project errors. Always install Sass as a local dev dependency to ensure your project is self-contained.
Why Does The Error Appear After Cloning A Repository?
The node_modules folder is not included in version control. You must run npm install after cloning to download all dependencies, including Sass.
Does The Error Affect Production Builds?
Yes, the error stops your build process entirely. You must fix it before deploying your application to production.
Final Checklist To Resolve Can Not Find Module Sass
Use this quick checklist to systematically eliminate the error.
- Run
npm install sass --save-devin your project root - Delete
node_modulesand reinstall if the error persists - Check your
package.jsonfor thesassentry - Verify your build tool configuration (Webpack, Vite, Gulp, etc.)
- Ensure no global Sass installation is interfering
- Check for typos in import statements and file extensions
- Clear npm cache and try again
- Use
node-sassas a temporary workaround if needed
Most developers resolve this error within minutes by installing the missing package. The key is to always keep your dependencies up to date and installed locally.
Once you fix the error, your Sass files will compile correctly, and your styles will appear as expected. Remember to commit your lock file and run npm install after every clone to prevent future occurences.
If you continue to see the error after trying all these steps, check your Node.js version and update it if necessary. Some older versions have compatibility issues with the latest Sass releases.
With these solutions, you can confidently handle the “can not find module sass” error and get back to building your project.