You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 of postcssrc call at
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
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
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.
+1 same problem for me using vitest for tests. To bypass this issue, you can change your postcss config to: postcss.config.json. It seems this file format is not loaded automatically by vitest.
BUT, unfortunately I am unable to do this in my cause because I have custom rules/imports in my postcss.config.cjs file and when I move to postcss.config.json I lose all of that functionality 😞 I suspect others will have this issue as well.
This has actually become a blocker for my team and we have continually failing tests in our pipelines because of this.
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 atvite/packages/vite/src/node/plugins/css.ts
Line 1574 in dad7f4f
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
The text was updated successfully, but these errors were encountered: