vitejs / vite

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

postcss config should not be searched outside of project root #16227

Open pqnet opened 3 months ago

pqnet commented 3 months ago

Describe the bug

The default behavior of postcss-load-config is to search configuration in the parent directory until it either find some matching file or reaches the home directory.

It will look for files named package.json or any of the postcss default configuration files.

This can result in unpredictable outcome of cloud builds and such. Moreover, if any of such files exists but is not readable/not a file, the error message does not narrow down the issue to the file causing the problem but reports a generic "failed to load PostCSS config" error.

The correct behavior should be to not search outside of the project.

To solve this issue it would be advisable to either

If neither is possible it would advisable to generate an empty .postcssrc.json during the initial scaffolding (npm create vite), although this should propagate to other generators using Vite as well such as npm create vue

Reproduction

n/a

Steps to reproduce

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 12.84 GB / 15.60 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  npmPackages:
    vite: ^5.2.2 => 5.2.2

Used Package Manager

npm

Logs

No response

Validations

pqnet commented 3 months ago

related documentation:

https://github.com/postcss/postcss-load-config/blob/865523080f8f39559b3c6570fe1c70fc593eeb61/src/index.d.ts#L7 https://www.npmjs.com/package/lilconfig

jacobbogers commented 3 weeks ago

I encountered this issue while debugging through vite code, this is not good issue, because it is very hard to resolve if it occurs

if any of these files below are found in the os.user() dir (or parent dir thereof) it will use that if it is not defined in project root

[
  "package.json",
  ".postcssrc",
  ".postcssrc.json",
  ".postcssrc.yaml",
  ".postcssrc.yml",
  ".postcssrc.ts",
  ".postcssrc.cts",
  ".postcssrc.js",
  ".postcssrc.cjs",
  ".postcssrc.mjs",
  "postcss.config.ts",
  "postcss.config.cts",
  "postcss.config.js",
  "postcss.config.cjs",
  "postcss.config.mjs",
]