Module build failed: TypeError: Cannot read property 'postcss' of undefined
See original GitHub issueSeeing this error when I try to incorporate postcss with webpack:
Module build failed: TypeError: Cannot read property 'postcss' of undefined
at Processor.normalize (/Users/tmaximini/data/frontend-node/node_modules/postcss-loader/node_modules/postcss/lib/processor.js:53:18)
at new Processor (/Users/tmaximini/data/frontend-node/node_modules/postcss-loader/node_modules/postcss/lib/processor.js:23:29)
at postcss (/Users/tmaximini/data/frontend-node/node_modules/postcss-loader/node_modules/postcss/lib/postcss.js:55:12)
at Object.module.exports (/Users/tmaximini/data/frontend-node/node_modules/postcss-loader/index.js:46:5)
Webpack Config
const path = require('path');
const webpack = require('webpack');
const cssnano = require('cssnano');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const stylesPath = path.resolve(__dirname, 'client/styles');
module.exports = {
devtool: false,
entry: {
app: __dirname + '/client/Entry.js'
},
output: {
path: __dirname + '/public/dist/',
filename: 'bundle.js',
chunkFilename: '[name].js',
publicPath: '/dist/'
},
plugins: [
new webpack.DefinePlugin({
'__DEV__': false // set global variable __DEV__ to true
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false
}
}),
new ExtractTextPlugin('css/[name].[contenthash:5].css', {
disable: false,
allChunks: true
}),
new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js')
],
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style',
'css!postcss!sass'
)
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react', 'react-hmre', 'stage-0']
}
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
postcss: cssnano({
autoprefixer: {
add: true,
remove: true,
browsers: ['last 2 versions']
},
discardComments: {
removeAll: true
},
discardUnused: false,
mergeIdents: false,
reduceIdents: false,
safe: true,
sourcemap: true
})
};
If I remove !postcss
from the Loaders it builds fine.
"postcss-loader": "^0.8.0",
"css-loader": "^0.23.1",
"cssnano": "^3.5.2",
"sass-loader": "^3.2.0",
"style-loader": "^0.13.0",
thanks in advance.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Webpack + postcss Cannot read properties of undefined ...
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js): TypeError: Cannot read properties of undefined (reading 'syntax').
Read more >postcss-loader - npm
Start using postcss-loader in your project by running `npm i ... Default: undefined ... Allows to set PostCSS options and plugins.
Read more >Webpack 4 css modules TypeError Cannot read property ...
client/src/common/accordian-component/accordian.css) Module build failed: TypeError: Cannot read property 'context' of undefined at Object.
Read more >Cannot read property \\\'length\\\' of undefined
Hello guys. Ive just downloaded https://git.mdbootstrap.com/mdb/jquery/jq-pro and I have problem whenever i try to use PRO scss.
Read more >Open side panel - You.com
css Module build failed (from . ... node_modules/postcss-loader/dist/cjs.js): TypeError: Cannot read property '0' of undefined at ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just for the record, I got the same error when using old postcss version with webpack 4 config.
postcss entry expect a function that returns postcss plugins, not directly a postcss plugins. Change
postcss: cssnano(
topostcss: function () { return [ cssnano(
or something like that. Please read the documentation and example in the README.