Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Can't find stylesheet to import. #801

Closed
dagda1 opened this issue Aug 17, 2019 · 10 comments
Closed

Error: Can't find stylesheet to import. #801

dagda1 opened this issue Aug 17, 2019 · 10 comments

Comments

@dagda1
Copy link

dagda1 commented Aug 17, 2019

I have a sass file that imports a file from node_modules using the tilde prefix:

@import '~@cutting/component-library/src/styles/_index.scss';

When I try and run this using renderSync I get the following error:

3 │ @import '~@cutting/component-library/src/styles/_index.scss';
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Users/paulcowan/projects/cuttingedge/packages/website/src/assets/scss/_main.scss 3:9 @import
stdin 1:9 root stylesheet
at Object._newRenderError (/Users/paulcowan/projects/cuttingedge/node_modules/sass/sass.dart.js:10687:19)
at Object._wrapException (/Users/paulcowan/projects/cuttingedge/node_modules/sass/sass.dart.js:10537:16)
at StaticClosure._renderSync (/Users/paulcowan/projects/cuttingedge/node_modules/sass/sass.dart.js:10512:18)
at Object.Primitives_applyFunction (/Users/paulcowan/projects/cuttingedge/node_modules/sass/sass.dart.js:1055:30)
at Object.Function_apply (/Users/paulcowan/projects/cuttingedge/node_modules/sass/sass.dart.js:4882:16)

This works when I use the sass-loader and webpack to parse the files like this.

I am trying to fix a bug in typescript-plugin-css-modules which uses sass-dart and I would be interested to know if sass-dart supports tilde imports?

I have a failing test which you can reproduce like this:

git clone https://github.com/dagda1/typescript-plugin-css-modules.git
cd typescript-plugin-css-modules
npm install
git checkout pc/tilde-import
npm test

The test file is here and the fixture it uses here

@dagda1
Copy link
Author

dagda1 commented Aug 17, 2019

actually, the ~ was a workaround in the sass-loader that was fixed in this PR.

If I remove this tilde from my import and include node_modules in the includePaths in renderSync then all is good.

      transformedCss = sass
        .renderSync({
          data: css,
          includePaths: [
            filePath,
            'node_modules'
          ],
        })
        .css.toString();

@dagda1 dagda1 closed this as completed Aug 17, 2019
sounisi5011 added a commit to sounisi5011/sounisi5011.jp that referenced this issue Oct 18, 2019
@danny007in
Copy link

danny007in commented Nov 15, 2020

but how in dart-sass by https://www.npmjs.com/package/node-sass-package-importer using cli method node-sass --importer node_modules/node-sass-package-importer/dist/cli.js -o dist src/index.scss

@zaydek
Copy link

zaydek commented Nov 17, 2020

@danny007in Try using --load-path or -I:

-I, --load-path=<PATH>         A path to use when resolving imports.

@sattes-faction
Copy link

@zaydek unfortunately that doesn't work, because the '~' is not stripped.

@danny007in
Copy link

@zaydek unfortunately that doesn't work, because the '~' is not stripped.

u need to remove ~

@sattes-faction
Copy link

Yes I know, but it would be nice if dart sass could follow the webpack scheme here, because the ~ is also recognized across all IDEs properly. In my case I have the issue that a scss file using that import scheme is used by a webpack config and also by the cli dart sass (part of ongoing migration).

In node sass it was possible to use a custom importer using the --importer flag on command line, but that's not possible with dart sass (which is recommended by node sass).

@danny007in
Copy link

@sattes-faction create new issue for that

@mdownes
Copy link

mdownes commented Apr 7, 2022

@sattes-faction create new issue for that

Has an issue been created for this?. I have had to use the tilde-sass package to get around this.

@lonix1
Copy link

lonix1 commented May 24, 2022

@mdownes I also tried to use that node-sass-tilde-importer package but couldn't get it to work. What does your cli syntax look like, if you don't mind?

@mdownes
Copy link

mdownes commented May 24, 2022

@mdownes I also tried to use that node-sass-tilde-importer package but couldn't get it to work. What does your cli syntax look like, if you don't mind?

I just added this to my package.json

“Build:sass”:”tilde-sass —file src/styles.scss —outfile dist/“

My styles.scss looked something like this:

@use “~/somedirectory/somefile.scss”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants