Skip to content

Sass loader doesn't support importing from node_modules without ~ #14

Description

@hmidmrii

I'm facing an issue when trying to use storybook + vite on my components lib, because vite scss loader doesn't
need ~ to resolve imports from node_modules, but this lib needs to (and SCSS standards as far as I know), so I did add an importer for the scss property from the options that handles this issue, and I think it should be included in the default scss importer.

I took the importer from your package and changed it a bit to the following:

importer: (url: string, importer: string) => {
  if (path.isAbsolute(url) || url.startsWith('.')) return null;

  const partialUrl = getUrlOfPartial(url);

  const options = {
    caller: 'Sass importer',
    basedirs: [path.dirname(importer)],
    extensions: stylesExtensions,
    packageFilter: packageFilterBuilder({ conditions }),
  };

  try {
    return finalize(resolveSync([partialUrl, url], options));
  } catch {
    return null;
  }
}

we can improve even the default importer you have to handle both cases,

I'll try to open a PR to handle them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions