postcss-loader: Webpack 2 + postcss-loader 1: TypeError: Cannot read property 'config' of null
Using Webpack 2 with postcss-loader 1.0 produces:
TypeError: Cannot read property 'config' of null
at .../node_modules/postcss-load-config/index.js:50:22
Is my webpack.config.js syntax in order?
module: { rules: [ { test: /\.jsx?$/, include: paths.src, use: { loader: 'babel' } }, { test: /\.s?css/, use: [ { loader: 'style-loader', options: { sourceMap: true } }, { loader: 'css-loader', options: { importLoaders: 1, modules: true, localIdentName: '[path]_[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: true, plugins: () => [] }, { loader: 'sass-loader', options: { sourceMap: true } } ] }
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 46 (16 by maintainers)
Same “Config could not be loaded” error here. I don’t have an external config file but I’m adding plugins inline:
It is just a warning, when you didn’t provide any plugins to PostCSS.
Both your config had no plugins, just set plugins and warning will be removed 😊.
We fixed this issue, just waiting for postcss-load-config release.
This is working!
Webpack 2.1.0-beta.25
Right. Loading plugins with webpack2 doesn’t work yet.
I took the time to investigate more why it’s not working and found it’s because of a bug when style-loader is in the loader chain.
webpack/webpack#3136 for reference.
Possible solutions:
Using webpack2 + postcss-loader 1.1, warning is now:
How do I fix this ?
@DylanPiercey
PostCSS config:
Package details:
I’m seeing the same warning in v2.1.0-beta.27 but only when style-loader is in my chain.
I also noticed that if I set
plugins:
to[]
instead of() => []
everything works as expected without style-loader, but completely blows up the build when style-loader is in the chain and I get a more cryptic warning:Module build failed: TypeError: Cannot read property 'postcss' of null
Which is weird, because I’d expect it to fail regardless of whether or not style-loader is in the chain.
Here’s his full config file for reference
http://pastebin.com/Lmka3rju
@ai released 👍 @lourd
It works when I use a
postcss.config.js
or.postcssrc
file in the top directory of my project, using these formats:It does not work when I export a function, as
postcss-load-config
would lead me to believeIt also does not work when I put the config file somewhere other than the top level directory, such as in
config/
. I thought that might “just work” after reading thecosmiconfig
docs, but it looks like they’re swapping what I normally think of as “lower” or “higher” in the filesystem – no “just working” there. If I’m going to have to specify my postcss config separately from my webpack config, I would strongly prefer to at least keep it out of the main directory.Are you sure this is just a warning? because I tried to setup webpack 2 + postcss-loader 1 and couldn’t get it to work.