node-sass-magic-importer is a custom importer for node-sass that significantly extends its `@import` capabilities. It integrates several specialized functionalities, including selector-specific imports (allowing users to import only certain CSS selectors or nodes from a file, with optional renaming/transformation), automatic `node_modules` resolution without requiring full paths, and globbing support for importing multiple files with a single pattern (e.g., `scss/**/*.scss`). Additionally, it features de-duplication logic to prevent importing the same file multiple times, except when filters are explicitly applied. The current stable version is 5.3.3, and the package maintains an active release cadence for node-sass compatibility. Its primary differentiator is the consolidation of these advanced import features into a single, configurable plugin, streamlining complex Sass import strategies.
npm install node-sass-magic-importerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `node-sass-magic-importer` with `node-sass` to leverage selector filtering from a node module (like Bootstrap) and glob importing for local components. It shows defining an importer, compiling Sass, and handling the output.
Consider migrating to Dart Sass (the `sass` package) and exploring its built-in module system (`@use`, `@forward`) or alternative globbing solutions if `node-sass` becomes a blocker. There is no direct drop-in replacement for all magic-importer features in Dart Sass.
Ensure your Node.js environment is updated to version 6.11.1 or higher to use `node-sass-magic-importer` v5.3.0 and later.
When configuring `node-sass`, ensure you pass `magicImporter()` (with parentheses) to the `importer` option, not `magicImporter` (without parentheses). Correct: `importer: magicImporter()`. Incorrect: `importer: magicImporter`.
Upgrade to `node-sass-magic-importer` version 5.3.2 or later to ensure correct TypeScript type resolution.
First, try `npm rebuild node-sass`. If that fails, ensure your Node.js version is compatible with your `node-sass` version (check `node-sass` documentation for supported Node versions), and that you have necessary build tools (like Python and C++ compiler) installed on your system.
Change `importer: magicImporter` to `importer: magicImporter()`.
Verify your glob patterns are correct and match existing files. Ensure `includePaths` includes your `node_modules` directory (`path.join(process.cwd(), 'node_modules')`) if you're importing packages from there. Also check for typos in file paths or selector filters.