vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.15k stars 6.15k forks source link

SassError: Can't find stylesheet to import when it contains @forward with _index file #4140

Closed mashirozx closed 2 years ago

mashirozx commented 3 years ago

Describe the bug

10:13:27 AM [vite] Internal server error: Can't find stylesheet to import.
  ╷
1 │ @use "@material/chips/mdc-chips";
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  src/styles/index.scss 1:1  @import
  src/App.vue 3:9            root stylesheet
  Plugin: vite:css
  File: /Users/***/styles/index.scss
  Error: Can't find stylesheet to import.
    ╷
  1 │ @use "@material/chips/mdc-chips";
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵

The _index.scss of this dep contains @forward rules.

More information:

There is the same problem in webpack, but can be solved like this, but I haven't see options like this in Vite's documentation.

Reproduction

  1. yarn add @material/chips@canary
  2. In a new Vue3 template project.
  3. @use the dep's style following documentation:
    <style lang="scss">
    @use "@material/chips/mdc-chips";
    </style>

System Info

System:
    OS: macOS 11.4
    CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
    Memory: 73.38 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm
  Browsers:
    Chrome: 91.0.4472.114
    Firefox: 89.0.1
    Safari: 14.1.1
  npmPackages:
    @vitejs/plugin-vue: ^1.2.4 => 1.2.4 
    vite: ^2.3.8 => 2.3.8

Used Package Manager

yarn

Logs

yarn run v1.22.10
$ vite build --debug
  vite:config bundled config file loaded in 220ms +0ms
  vite:config using resolved config: {
  vite:config   base: 'http://localhost:9000/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object], [Object] ] },
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'svgicon',
  vite:config     'vite:dynamic-import-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:manifest',
  vite:config     'vite:reporter'
  vite:config   ],
  vite:config   server: {
  vite:config     host: '0.0.0.0',
  vite:config     cors: true,
  vite:config     strictPort: true,
  vite:config     port: 9000,
  vite:config     hmr: { protocol: 'ws', host: 'localhost', port: 9000 },
  vite:config     fsServe: { root: '/Users/****/wd/****', strict: false }
  vite:config   },
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillDynamicImport: false,
  vite:config     outDir: 'app/assets/dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: true,
  vite:config     rollupOptions: {},
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     cleanCssOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: true,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     brotliSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null
  vite:config   },
  vite:config   css: { preprocessorOptions: { scss: [Object] } },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: '/Users/****/wd/****/vite.config.ts',
  vite:config   configFileDependencies: [ 'vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/Users/****/wd/****',
  vite:config   publicDir: '/Users/****/wd/****/public',
  vite:config   cacheDir: '/Users/****/wd/****/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   env: {
  vite:config     BASE_URL: 'http://localhost:9000/',
  vite:config     MODE: 'production',
  vite:config     DEV: false,
  vite:config     PROD: true
  vite:config   },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: { esbuildOptions: { keepNames: undefined } }
  vite:config } +7ms
vite v2.3.8 building for production...
transforming (69) node_modules/camelcase-keys/index.js  vite:resolve 0ms   /src//styles/mixins/skeleton -> /Users/****/wd/****/src/styles/mixins/_skeleton.scss +0ms
  vite:resolve 0ms   @/styles/mixins/skeleton -> /Users/****/wd/****/src/styles/mixins/_skeleton.scss +0ms
  vite:resolve 22ms  /src//styles/index.scss -> /Users/****/wd/****/src/styles/index.scss +415ms
  vite:resolve 23ms  @/styles/index.scss -> /Users/****/wd/****/src/styles/index.scss +1ms
transforming (80) node_modules/@vue/devtools-api/lib/esm/api/index.js  vite:resolve 3ms   @material/chips/mdc-chips -> null +200ms
✓ 95 modules transformed.
[vite:css] Can't find stylesheet to import.
  ╷
1 │ @use "@material/chips/mdc-chips";
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  src/styles/index.scss 1:1  @import
  src/App.vue 3:9            root stylesheet
file: /Users/****/wd/****/src/App.vue?vue&type=style&index=0&lang.scss
Error: Can't find stylesheet to import.
  ╷
1 │ @use "@material/chips/mdc-chips";
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  src/styles/index.scss 1:1  @import
  src/App.vue 3:9            root stylesheet
error during build:
Error: Can't find stylesheet to import.
  ╷
1 │ @use "@material/chips/mdc-chips";
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  src/styles/index.scss 1:1  @import
  src/App.vue 3:9            root stylesheet
    at Object._newRenderError (/Users/****/wd/****/node_modules/sass/sass.dart.js:13222:19)
    at Object._wrapException (/Users/****/wd/****/node_modules/sass/sass.dart.js:13050:16)
    at _render_closure1.call$2 (/Users/****/wd/****/node_modules/sass/sass.dart.js:81775:21)
    at _RootZone.runBinary$3$3 (/Users/****/wd/****/node_modules/sass/sass.dart.js:27547:18)
    at _FutureListener.handleError$1 (/Users/****/wd/****/node_modules/sass/sass.dart.js:26096:19)
    at _Future__propagateToListeners_handleError.call$0 (/Users/****/wd/****/node_modules/sass/sass.dart.js:26394:49)
    at Object._Future__propagateToListeners (/Users/****/wd/****/node_modules/sass/sass.dart.js:4541:77)
    at _Future._completeError$2 (/Users/****/wd/****/node_modules/sass/sass.dart.js:26226:9)
    at _AsyncAwaitCompleter.completeError$2 (/Users/****/wd/****/node_modules/sass/sass.dart.js:25880:12)
    at Object._asyncRethrow (/Users/****/wd/****/node_modules/sass/sass.dart.js:4340:17)
error Command failed with exit code 1.

Validations

jjstanton commented 3 years ago

Hi,

I am also having the same issue with importing various components from Material.

@mashirozx have you managed to figure out a workaround in the meantime?

mashirozx commented 3 years ago

Nope till now, I just @use the forward targets directly.

jjstanton commented 3 years ago

@mashirozx would you mind sharing an example please?

mashirozx commented 3 years ago

here, https://github.com/mashirozx/sakura/blob/next/src/admin/_mdc.scss

lampewebdev commented 3 years ago

I'm having the same problem with @use

  Error: Can't find stylesheet to import.
    ╷
  1 │ @use "~@online/vue-global/scss/animations" as animations;
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵

I'm using vite 2.5.4 and sass 1.40.1

jrson83 commented 2 years ago

Same issue. I wanted to switch from @import to @use and @forward. It is not possible because Vite is throwing the error.

[vite] Internal server error: Can't find stylesheet to import.
  ╷
3 │ @use 'abstracts';
  │ ^^^^^^^^^^^^^^^^

Vite 2.8.4 and SASS 1.49.8. This issue should be fixed please, since @import will be soon deprecated,

sapphi-red commented 2 years ago

@mashirozx I was able to reproduce. But @material/chips/mdc-chips does not exist. So I think this is working correctly. Currently the docs says to do @use "@material/chips/styles";. Was the docs not had updated? If you change it to that, it works without error. https://stackblitz.com/edit/vitejs-vite-u1eckg?file=src%2FApp.vue&terminal=dev

Also the reproduction at https://github.com/webpack-contrib/sass-loader/issues/804 works properly with vite.

mashirozx commented 2 years ago

@sapphi-red the dependency version should be locked: "@material/chips": "^13.0.0-canary.08398f880.0",

sapphi-red commented 2 years ago

@mashirozx It seems there is no @material/chips/mdc-chips in that version. https://www.jsdelivr.com/package/npm/@material/chips?version=13.0.0-canary.08398f880.0

mashirozx commented 2 years ago

Well, seems so, I can't find which version I was using at the time I open this issue. But I'm sure that the @forward rule doesn't work well on Vite, we can reproduce the issue by something else, like https://cdn.jsdelivr.net/npm/@material/chips@13.0.0-canary.08398f880.0/_index.scss

sapphi-red commented 2 years ago

@mashirozx Is this what you intend? I think it is working well. https://stackblitz.com/edit/vitejs-vite-u93kky?file=src%2FApp.vue&terminal=dev

github-actions[bot] commented 2 years ago

Hello @mashirozx. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

mashirozx commented 2 years ago

Sadly, I didn't save the code at that time, and also doesn't remember the detail to reproduce (seems @material/chips has huge upgrade since then and I can't find the old docs). But I'm pretty sure the @forward issue with at least vite^2.4.2. Can anyone else provide the reproduction? @jjstanton @lampewebdev @jrson83

lampewebdev commented 2 years ago

We stooped using ˜ because vite does not come with that alias out of the box like vue-cli did.

So we have refactored our code.

Instead of using:

@use "˜@something/css/file.css";

we are using:

@use "node_modules/@something/css/file.css";

EDIT: Looking at the repo I think our problem was this: https://stackblitz.com/edit/vitejs-vite-fw386x?file=src%2FApp.scss&terminal=dev but again with @ or node_modules it works fine