vite
vite copied to clipboard
postcss config should not be searched outside of project root
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
- lobby to change the default
postcss-load-config
behavior (although it may be by design in their case) - workaround it at Vite level by passing the absolute path of the project dir as
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):
result = postcssrc({}, searchPath, { stopDir }).catch((e) => {
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
-
mkdir -p parent/child
-
mkdir parent/package.json
-
cd parent/child
-
npm init es6 -y
-
npm i [email protected]
-
touch index.html
-
npx vite
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.