sveltejs / svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
MIT License
1.76k stars 151 forks source link

includePaths not working for imports with @use #512

Closed esheehan-gsl closed 2 years ago

esheehan-gsl commented 2 years ago

Describe the bug I get a Can't find stylesheet to import error despite setting includePaths when I configure svelte-preprocess.

To Reproduce https://github.com/esheehan-gsl/svelte-preprocess-includepaths-cant-import-stylesheet

Clone the above repo and run npm run dev to see the import error.

Expected behavior The dev server should start up without error, and http://localhost:3000 should load styles.css.

Stacktraces If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace ``` Can't find stylesheet to import. ╷ 1 │ @use "uswds-core"; │ ^^^^^^^^^^^^^^^^^ ╵ src/_uswds-theme.scss 1:1 @use src/styles.scss 1:1 root stylesheet Can't find stylesheet to import. ╷ 1 │ @use "uswds-core"; │ ^^^^^^^^^^^^^^^^^ ╵ src/_uswds-theme.scss 1:1 @use src/styles.scss 1:1 root stylesheet Error: Can't find stylesheet to import. ╷ 1 │ @use "uswds-core"; │ ^^^^^^^^^^^^^^^^^ ╵ src/_uswds-theme.scss 1:1 @use src/styles.scss 1:1 root stylesheet Error: Can't find stylesheet to import. ╷ 1 │ @use "uswds-core"; │ ^^^^^^^^^^^^^^^^^ ╵ src/_uswds-theme.scss 1:1 @use src/styles.scss 1:1 root stylesheet at Object.wrapException (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:1254:17) at /home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:69695:25 at _wrapJsFunctionForAsync_closure.$protected (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:3737:15) at _wrapJsFunctionForAsync_closure.call$2 (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:28043:12) at _awaitOnObject_closure.call$1 (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:28031:32) at Object._rootRunUnary (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:4139:18) at StaticClosure. (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:97718:16) at _CustomZone.runUnary$2$2 (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:29458:39) at _Future__propagateToListeners_handleValueCallback.call$0 (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:28515:51) at Object._Future__propagateToListeners (/home/evan/Code/svelte-preprocess-includepaths-cant-import-stylesheet/node_modules/sass/sass.dart.js:3934:93) ```

Information about your project:

Additional context For comparison, you can run npm run sass, which runs sass with the --load-path argument using the same path that’s set as the includePaths in the SvelteKit config—this works, making me think the issue is with svelte-preprocess and not Sass or USWDS.

This may be related to #476.

esheehan-gsl commented 2 years ago

Apologies. This was my mistake. I was using

<script>
  import '../styles.scss';
</script>

to load the stylesheet, which was processing it through Vite, not svelte-preprocess. That's why my configuration for svelte-preprocess wasn't working. If I use a <style> tag in the component, Sass is able to resolve the modules.

<style lang="scss">
  @forward "src/styles.scss";
</style>