Skip to content

Support for SASS nodeJS package importer #16438

Closed
@kkesidis

Description

@kkesidis

Describe the bug

I am making a generic app that that offers both a SASS and a CSS stylesheet to users, so they can use whichever suits their needs. However, there is an issue with the import of node packages.

SASS now has the --pkg-importer=node option that allows it to load dependencies using the Node.js module resolution algorithm. Using this CLI option i can import a path that is defined on the package.json "export".

@use "pkg:path/to/file.scss"

However, the above does not work in the context of a node app. With that, i mean that if we try to import the .scss containing the above code in a main.js file, we'll get:

Error: Can't find stylesheet to import.

I checked the documentation but couldn't find a way to configure this or add the SASS importer as seen on the sass example.

I would expect that we can use the supported pkg: prefix to both build the SASS/SCSS file to css and serve a node app using that same code, or at least be able to configure the css options to enable that support.

Note: I understand that bootstrap does not have an "exports" property in their package.json. I used it for a simple example, the behavior is the same with packages that define "export".

Reproduction

https://github.com/kkesidis/vite-sass-pkg-prefix

Steps to reproduce

  1. Run yarn build:scss to build the css file. This will succed.
  2. Run `yarn build" to build the app (which also imports the scss file)

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (12) x64 AMD Ryzen 5 2600X Six-Core Processor
    Memory: 11.26 GB / 12.43 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.12.2/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^5.0.4 => 5.0.4
    vite: ^5.2.0 => 5.2.9

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat: cssp2-nice-to-haveNot breaking anything but nice to have (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions