webpack-contrib / postcss-loader

PostCSS loader for webpack
MIT License
2.86k stars 211 forks source link

Build breaks when .config is a file #662

Closed Eboreg closed 8 months ago

Eboreg commented 1 year ago

Bug report

After upgrading postcss-loader from 6.2.1 to 7.3.3, Webpack build failed because I have a file in my project root called .config, and no PostCSS specific config outside of my main Webpack config. After adding an empty postcss property in package.json, the problem ceases.

N.B. Not sure if this is specific to these mentioned postcss-loader versions. I'm guessing it has to do with the associated upgrade of cosmiconfig from 7.0.1 to 8.2.0.

Actual Behavior

Output on Webpack build, without postcss entry in package.json or any PostCSS specific config file:

ERROR in ./assets/css/style.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Error: ENOTDIR: not a directory, open '/home/klaatu/kod/edu-lms/.config/postcssrc'
    at tryRunOrWebpackError (/home/klaatu/kod/edu-lms/node_modules/webpack/lib/HookWebpackError.js:88:9)
    at __webpack_require_module__ (/home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5067:12)
    at __webpack_require__ (/home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5024:18)
    at /home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5095:20
    at symbolIterator (/home/klaatu/kod/edu-lms/node_modules/neo-async/async.js:3485:9)
    at done (/home/klaatu/kod/edu-lms/node_modules/neo-async/async.js:3527:9)
    at Hook.eval [as callAsync] (eval at create (/home/klaatu/kod/edu-lms/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5002:43
    at symbolIterator (/home/klaatu/kod/edu-lms/node_modules/neo-async/async.js:3482:9)
    at timesSync (/home/klaatu/kod/edu-lms/node_modules/neo-async/async.js:2297:7)
-- inner error --
Error: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Error: ENOTDIR: not a directory, open '/home/klaatu/kod/edu-lms/.config/postcssrc'
    at Object.<anonymous> (/home/klaatu/kod/edu-lms/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].use[1]!/home/klaatu/kod/edu-lms/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].use[2]!/home/klaatu/kod/edu-lms/node_modules/resolve-url-loader/index.js!/home/klaatu/kod/edu-lms/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[6].use[4]!/home/klaatu/kod/edu-lms/assets/css/style.scss:1:7)
    at /home/klaatu/kod/edu-lms/node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js:452:10
    at Hook.eval (eval at create (/home/klaatu/kod/edu-lms/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at /home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5069:39
    at tryRunOrWebpackError (/home/klaatu/kod/edu-lms/node_modules/webpack/lib/HookWebpackError.js:83:7)
    at __webpack_require_module__ (/home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5067:12)
    at __webpack_require__ (/home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5024:18)
    at /home/klaatu/kod/edu-lms/node_modules/webpack/lib/Compilation.js:5095:20
    at symbolIterator (/home/klaatu/kod/edu-lms/node_modules/neo-async/async.js:3485:9)
    at done (/home/klaatu/kod/edu-lms/node_modules/neo-async/async.js:3527:9)

Generated code for /home/klaatu/kod/edu-lms/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].use[1]!/home/klaatu/kod/edu-lms/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].use[2]!/home/klaatu/kod/edu-lms/node_modules/resolve-url-loader/index.js!/home/klaatu/kod/edu-lms/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[6].use[4]!/home/klaatu/kod/edu-lms/assets/css/style.scss
1 | throw new Error("Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):\nError: ENOTDIR: not a directory, open '/home/klaatu/kod/edu-lms/.config/postcssrc'");
 @ ./assets/ts/entrypoints/base.ts 1:0-30

Expected Behavior

.config being a file instead of a directory should not cause the build to fail IMO, even if no higher priority config files exist.

How Do We Reproduce?

Install Webpack with postcss-loader 7.3.3 with cosmiconfig 8.2.0. Make .config a file. Try to build.

Please paste the results of npx webpack info here, and mention other relevant information

  System:
    OS: Linux 5.19 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz
    Memory: 10.74 GB / 23.34 GB
  Binaries:
    Node: 18.17.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.6.7 - /usr/bin/npm
  Packages:
    babel-loader: ^8.2.2 => 8.2.5 
    clean-webpack-plugin: ^4.0.0 => 4.0.0 
    css-loader: ^6.0.0 => 6.7.1 
    expose-loader: ^4.0.0 => 4.0.0 
    postcss-loader: ^7.3.3 => 7.3.3 
    resolve-url-loader: ^5.0.0 => 5.0.0 
    sass-loader: ^13.3.2 => 13.3.2 
    ts-loader: ^9.4.4 => 9.4.4 
    webpack: ^5.88.2 => 5.88.2 
    webpack-bundle-tracker: ^2.0.1 => 2.0.1 
    webpack-cli: ^5.1.4 => 5.1.4 
alexander-akait commented 8 months ago

Sorry for delay, it was a bug in cosmiconfig, fixed here https://github.com/cosmiconfig/cosmiconfig/releases/tag/cosmiconfig-v8.3.6, please update your deps, feel free to feedback