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

sass-loader can't resolve path to _index.scss file when using import alias #691

Closed
sqal opened this issue Jun 5, 2019 · 6 comments · Fixed by #727
Closed

sass-loader can't resolve path to _index.scss file when using import alias #691

sqal opened this issue Jun 5, 2019 · 6 comments · Fixed by #727

Comments

@sqal
Copy link

sqal commented Jun 5, 2019

  • Operating System: Windows 10
  • Node Version: 12.2.0
  • NPM Version: 6.9.0
  • webpack Version: 4.33.0
  • sass-loader Version: 7.1.0

Issue

Dart-sass allows us to import an _index.scss or _index.sass file without explicitly adding the _index part at the end of imported file. Currently it only works for relative imports and fails when I try to import _index.scss using an alias in my import path.

Expected Behavior

This code should work

// @/scss is an alias to some-absolute-path/scss and functions/_index.scss exists
@import "~@/scss/functions";

Actual Behavior

Compilation failed

ERROR in ./src/style.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/lib/loader.js??ref--4-2!./src/style.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import "~@/scss/functions";
       ^
      Can't find stylesheet to import.
  ╷
5 │ @import "~@/scss/functions";
  │         ^^^^^^^^^^^^^^^^^^^
  ╵
  stdin 5:9  root stylesheet
      in C:\dev\sass-test\src\style.scss (line 5, column 9)
 @ ./src/style.scss 2:14-130
 @ ./src/index.js

Code

Reproduction https://github.com/sqal/sass-loader-bug-repro

How Do We Reproduce?

  • clone my reproduction repositor and try build the project (npm run build)
  • also please check my comment in src/style.scss
@alexander-akait
Copy link
Member

What you expected? You should use package name, like ~@bootstrap/scss/functions

@sqal
Copy link
Author

sqal commented Jun 5, 2019

@evilebottnawi ~@bootstrap/scss/functions ? why bootstrap? I don't use bootstrap. Have you checked my reproduction? I just want to import an _index.scss file e.g. @import "~@/scss/functions" which should resolve to e.g. C:\my-project\packages\scss\functions\_index.scss but it currently doesn't work without adding /_index to the path. I listed all possible options for importing scss file in my reproduction repo (src/syle.scss)

I don't know much about sass-loader source code but propably {request}/_index.{scss,sass} case should be handled here (I could be wrong though :P) https://github.com/webpack-contrib/sass-loader/blob/master/lib/importsToResolve.js#L51 (

// Yup actually adding these paths to the list fixes the issue

`${request}/_index.scss`,
`${request}/_index.sass`,

@imkremen
Copy link

@sqal Looks like it's not related to sass-loader.
sass/node-sass#2339

@alexander-akait
Copy link
Member

alexander-akait commented Jun 10, 2019

Yes, it is node-sass feature

@sqal
Copy link
Author

sqal commented Jun 10, 2019

@evilebottnawi but I don't use node-sass :( I'm using dart-sass implementation and it supports importing _index file since version 1.0.0 https://github.com/sass/dart-sass/blob/master/CHANGELOG.md#100-rc1.

@alexander-akait
Copy link
Member

mark as feature, because it is support only sass (dart-sass)

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

Successfully merging a pull request may close this issue.

3 participants