express-dart-sass
raw JSON → 1.0.4 verified Sat Apr 25 auth: no javascript maintenance
Express middleware for dart-sass (the primary Sass implementation, now deprecated in favor of the new JS API). Version 1.0.4 is the latest stable release (last updated in 2021). It recompiles .scss/.sass files automatically for Express-based HTTP servers. Key differentiators: uses dart-sass (which is faster and more feature-complete than node-sass), supports legacy options like outputStyle, prefix, and error handling. The package is in maintenance mode due to the deprecation of the legacy JS API (LibSass/Node Sass) and the move to the new embedded dart-sass API.
Common errors
error Error: Cannot find module 'sass' ↓
cause The package depends on dart-sass (the `sass` npm package) which is not installed.
fix
npm install sass --save
error TypeError: sassMiddleware is not a function ↓
cause CommonJS require returns an object with a default property when using ESM-style import in a CJS environment? Actually, the package exports a function directly, but if you use `import sassMiddleware from 'express-dart-sass'` in a TypeScript project with esModuleInterop: false, it may cause issues.
fix
Use
const sassMiddleware = require('express-dart-sass') or enable esModuleInterop in tsconfig. Warnings
deprecated The dart-sass legacy JS API (used by this middleware) is deprecated in favor of the new compile() API. ↓
fix Consider migrating to sass (dart-sass) direct integration or use the new compile API in your own middleware.
gotcha Middleware must be placed before express.static to serve compiled CSS. ↓
fix Ensure app.use(sassMiddleware(...)) precedes app.use(express.static(...)).
gotcha The 'dest' option is required; if omitted, compiled files may overwrite source .scss files (since default is src). ↓
fix Always specify dest or use response: true if you don't need file output.
Install
npm install express-dart-sass yarn add express-dart-sass pnpm add express-dart-sass Imports
- default wrong
import sassMiddleware from 'express-dart-sass';correctconst sassMiddleware = require('express-dart-sass'); - default (ESM style) wrong
import { sass } from 'express-dart-sass';correctimport sassMiddleware from 'express-dart-sass'; // Works only if your project is configured for ESM interop. - Options interface wrong
import { Options } from 'express-dart-sass';correct// No type exports; define your own interface based on docs
Quickstart
const express = require('express');
const sassMiddleware = require('express-dart-sass');
const path = require('path');
const app = express();
app.use(sassMiddleware({
src: __dirname,
dest: path.join(__dirname, 'public'),
debug: true,
outputStyle: 'compressed',
prefix: '/prefix'
}));
app.use(express.static(path.join(__dirname, 'public')));
app.listen(3000, () => console.log('Server running on port 3000'));