vite: when i import the css file in less file, vite would throw error:no found file,but if i change the .css into .less would no error

Describe the bug

when i import css file in the less file, it would throw the error image

Reproduction

repoduction:

https://github.com/Jeromy-L/test-vite/tree/test2

branch :test2

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:


System:
    OS: macOS 11.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 118.15 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm
  Browsers:
    Chrome: 90.0.4430.93
    Safari: 14.0.2

Used package manager:

Logs

4:18:49 ├F10: PM┤ [vite] Internal server error: Failed to find 'base.css'
  in [
    /Users/xxx/Documents/project/test-vite/client/views
  ]
  Plugin: vite:css
  File: /Users/xxx/Documents/project/test-vite/client/views/Test.vue?vue&type=style&index=0&lang.less
      at /Users/xxx/Documents/project/test-vite/node_modules/vite/dist/node/chunks/dep-8dd46f43.js:65:13
      at async Promise.all (index 0)
      at async LazyResult.runAsync (/Users/xxx/Documents/project/test-vite/node_modules/vite/node_modules/postcss/lib/lazy-result.js:358:11)
      at async compileCSS (/Users/xxx/Documents/project/test-vite/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:18942:27)
      at async TransformContext.transform (/Users/xxx/Documents/project/test-vite/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:18574:50)
      at async Object.transform (/Users/xxx/Documents/project/test-vite/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:43780:30)
      at async transformRequest (/Users/xxx/Documents/project/test-vite/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:59429:29)
      at async /Users/xxx/Documents/project/test-vite/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:59566:32
  vite:time 61ms  /client/views/Test.vue?vue&type=style&index=0&lang.less +13ms


About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Bug in Vite Less Plugin. Need to enable the relativeUrls option.

i think i add the config into vite.config.js then will solve

css: {
    preprocessorOptions: {
      less: {
        relativeUrls: true,
      }
    }
  },