Skip to content

css.preprocessorOptions type error with sass importers #20150

@morganney

Description

@morganney

Describe the bug

I'm trying to use the sass pkg: importers by configuring a NodePackageImporter instance from sass-embedded in my css.preprocessorOptions but am encountering a type error:

Type 'NodePackageImporter' is not assignable to type 'NodePackageImporter | Importer<"async"> | FileImporter<"async">'.

If I use NodePackageImporter from sass instead, I get this error:

[vite:css] [sass] Error: TypeError: importer.findFileUrl is not a function

I saw this discussion reported a similar error: #17948

Reproduction

None

Steps to reproduce

My vite.config.ts configuration looks like this:

import {defineConfig} from 'vite';
import {NodePackageImporter} from 'sass-embedded';

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler',
        importers: [
          new NodePackageImporter(),
        ],
      },
    },
  },
});

The importers option seems to be typed from the sass package and not sass-embedded, so I do this to get around the type error:

import {defineConfig} from 'vite';
import {NodePackageImporter} from 'sass-embedded';
import {NodePackageImporter as DartSassPackageImporter} from 'sass';

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler',
        importers: [
          new NodePackageImporter() as unknown as DartSassPackageImporter,
        ],
      },
    },
  },
});

System Info

System:
    OS: macOS 15.4.1
    CPU: (14) arm64 Apple M4 Pro
    Memory: 2.64 GB / 24.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 22.15.0 - ~/n/bin/node
    npm: 10.9.2 - ~/n/bin/npm
    pnpm: 10.9.0 - ~/n/bin/pnpm
  Browsers:
    Chrome: 137.0.7151.68
    Safari: 18.4
  npmPackages:
    @vitejs/plugin-react: ^4.5.0 => 4.5.0 
    vite: ^6.3.5 => 6.3.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions