question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module build failed: TypeError: Cannot read property 'postcss' of undefined

See original GitHub issue

Seeing 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:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
siemiatjcommented, Jun 18, 2018

Just for the record, I got the same error when using old postcss version with webpack 4 config.

2reactions
MoOxcommented, Apr 14, 2016

postcss entry expect a function that returns postcss plugins, not directly a postcss plugins. Change postcss: cssnano( to postcss: function () { return [ cssnano( or something like that. Please read the documentation and example in the README.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found