Open pqnet opened 3 months 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",
]
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
postcss-load-config
behavior (although it may be by design in their case)stopDir
n the lilconfig options, (third parameter ofpostcssrc
call at https://github.com/vitejs/vite/blob/dad7f4f5a51433c2ac91a8aed1a5556a1e3fc640/packages/vite/src/node/plugins/css.ts#L1574-L1574):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 asnpm create vue
Reproduction
n/a
Steps to reproduce
mkdir -p parent/child
mkdir parent/package.json
cd parent/child
npm init es6 -y
npm i vite@5.2.2
touch index.html
npx vite
System Info
Used Package Manager
npm
Logs
No response
Validations