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. #5764

Closed
7 tasks done
svenvandescheur opened this issue Nov 19, 2021 · 2 comments
Closed
7 tasks done

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

svenvandescheur opened this issue Nov 19, 2021 · 2 comments

Comments

@svenvandescheur
Copy link

Describe the bug

Seems to be unresolved in latest release (2.6.14): #2499.

This issue has been reported before, and since the original issue is closed I assume it has a patch. However I encounter the same behaviour when attempting to load a css file from Leaflet.

Reproduction

@use "~leaflet/dist/leaflet.css";

Error: Failed to find '~leaflet/dist/leaflet.css'

@use "~leaflet/dist/leaflet.css";

Error: Can't find stylesheet to import.
â•·
1 │ @use "~leaflet/dist/leaflet.css";

System Info

System:
    OS: macOS 11.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 1.17 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.14.0 - /usr/local/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 7.7.6 - /usr/local/bin/npm
  Browsers:
    Chrome: 95.0.4638.69
    Edge: 95.0.1020.53
    Firefox: 93.0
    Safari: 14.1.1
  npmPackages:
    @vitejs/plugin-react: ^1.0.0 => 1.0.4 
    @vitejs/plugin-react-refresh: ^1.3.1 => 1.3.6 
    vite: ^2.6.14 => 2.6.14

Used Package Manager

npm

Logs

vite:time 18.31ms /src/Components/Map/Map.tsx +21ms
  vite:transform [reuse pending] for /src/Components/Map/Map.scss +18ms
4:59:34 PM [vite] Internal server error: Failed to find '~leaflet/dist/leaflet.css'
  in [
    /Users/svenvandescheur/PycharmProjects/open-inwoner/frontend/src/Components/Map
  ]
  Plugin: vite:css
  File: /Users/svenvandescheur/PycharmProjects/open-inwoner/frontend/src/Components/Map/Map.scss
      at /Users/svenvandescheur/PycharmProjects/open-inwoner/node_modules/vite/dist/node/chunks/dep-e39b05d6.js:74:13
      at async Promise.all (index 0)
      at async LazyResult.runAsync (/Users/svenvandescheur/PycharmProjects/open-inwoner/node_modules/postcss/lib/lazy-result.js:394:11)
      at async compileCSS (/Users/svenvandescheur/PycharmProjects/open-inwoner/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:20286:27)
      at async TransformContext.transform (/Users/svenvandescheur/PycharmProjects/open-inwoner/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:19876:50)
      at async Object.transform (/Users/svenvandescheur/PycharmProjects/open-inwoner/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:42396:30)
      at async doTransform (/Users/svenvandescheur/PycharmProjects/open-inwoner/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:56801:29)
  vite:time 25.84ms /src/Components/Map/Map.scss +32ms
  vite:time 12.75ms /src/assets/favicon.svg +143ms

Validations

@vikingair
Copy link

For me this helped, since vite module resolution tries to be consistent within stylesheet imports and JS imports and doesn' understand the very common usage of "~" in sass or scss. Add this to your defineConfig:

resolve: {
    alias: [
        {
            // this is required for the SCSS modules
            find: /^~(.*)$/,
            replacement: '$1',
        },
    ],
},

But be aware that this may collide with other aliases you want to support in your JS files.

@sapphi-red
Copy link
Member

@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants