vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.17k stars 6.04k forks source link

`lightningcss` is dynamically imported but not bundled or installed #17588

Closed thepassle closed 2 months ago

thepassle commented 2 months ago

Describe the bug

I wrote an eslint plugin that does some module graph analysis to avoid people from importing from barrel files. In order to do this, we crawl the module graph for the files in the users project. A user of my plugin submitted an issue to the eslint plugin because it seems to fail on the vite import in vite.config.ts. I can see that in the bundle of Vite (in dep-C1-ZB6nQ.js), the following dynamic import is present:

const importLightningCSS = createCachedImport(() => import('lightningcss'));

However, when I look in my node_modules, it seems like lightningcss is not installed:

image

Because lightningcss, the resolution library that I'm using (oxc-resolver) is unable to resolve lightningcss, because it's not installed.

Is this import for lightningcss left as a bare module specifier intentionally? Or could this be an oversight?

Reproduction

https://github.com/starkfire/barrel-vite

Steps to reproduce

npm i npm run lint

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 69.72 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v18.19.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
    pnpm: 8.14.1 - ~/.nvm/versions/node/v18.19.0/bin/pnpm
  Browsers:
    Chrome: 126.0.6478.127
    Chrome Canary: 128.0.6566.0
    Safari: 17.5
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    vite: ^5.3.1 => 5.3.2

Used Package Manager

npm

Logs

No response

Validations

bluwy commented 2 months ago

lightningcss is an optional peer dependency of Vite. Perhaps the resolver could check Vite's package.json peer deps?

thepassle commented 2 months ago

Hm, I dont think thats the responsibility of the module resolution algorithm, afaik most resolution libraries dont look at peerdependencies

thepassle commented 2 months ago

I think i'll just recommend people disable linting the config file for this plugin for now, the plugin is more concerned with source code rather than config files anyway