canirequire

canirequireCommonJS › node-sass

Is node-sass ESM-only? Can you require() it?

Wrapper around libsass

Latest version 9.0.0, published May 20, 2023. JSON

CommonJS CommonJS — require() works on every Node.js version

node-sass ships CommonJS only. require("node-sass") works everywhere. import "node-sass" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Latest
9.0.0 (May 20, 2023)
Module format
CommonJS
Last CommonJS version
9.0.0
TypeScript types
@types/node-sass
Node engines
>=16
Weekly downloads
888K
License
MIT

Deprecated: Node Sass is no longer supported. Please use `sass` or `sass-embedded` instead.

Does node-sass@9.0.0 actually load? Runtime test results

Runtime probe pending for this version. The values below are what package.json declares; they are refreshed once the probe runs.

Runtimerequire("node-sass")import "node-sass"
Node.js 18✓ expected✓ expected
Node.js 20✓ expected✓ expected
Node.js 22✓ expected✓ expected
Node.js 24✓ expected✓ expected
Node.js 26✓ expected✓ expected
Bun 1.4pendingpending

Install failed in our sandbox: error: postinstall script from "node-sass" exited with 1 The rows above show what package.json declares.

How to import node-sass

ES modules (import)

import nodeSass from "node-sass";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const nodeSass = require("node-sass");

Module format by version

Derived from the type, main and exports fields of every stable release on npm (132 versions; the newest 60 shown).

VersionsFormatFirst published
3.5.3 – 9.0.0CommonJSApr 21, 2016

Frequently asked

Is node-sass ESM-only?

node-sass@9.0.0 is a CommonJS package. node-sass ships CommonJS only. require("node-sass") works everywhere. import "node-sass" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Can I import node-sass with ES module syntax?

Yes. import nodeSass from "node-sass" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does node-sass ship TypeScript types?

Not bundled. Install the community types with "npm install -D @types/node-sass".

Links

Other commonjs packages

Similar popularity