Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

TypeError: [object Object] must be a function, did you require() it ? with Webpack 2 #63

Description

@gearboxdesign

Hi there,

First of all, great plugin, I found it really handy to use in a previous gulp based setup, does exactly what it says on the tin!

I seem to be having an issue with it in Webpack 2 though, the error:

'TypeError: [object Object] must be a function, did you require() it ?' referencing '/node_modules/postcss-load-plugins/lib/plugins.js' in the stack trace as the call site of the problem.

I have had no problems with the other postcss modules I use, seems to be either an issue specifically with post-css assets.

Without knowing much about the internals of postcss-load-plugins, as the error suggests it would seem to be expecting a function and not an object.

Is this a known issue or am I doing something wrong?

For reference (parts omitted for brevity):

webpack.config.js

...
module: {
    rules: [
      ...
    {
      test: /\.(sass|scss|css)$/,
      loader: ExtractTextPlugin.extract({
        fallbackLoader: 'style-loader',
        loader: [
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1
            }
          },
          { 
            loader: 'postcss-loader'
          }, 
          {
            loader: 'sass-loader',
            options: {
              includePaths: [
                paths.styles.main
              ]
            }
          }
        ]
      })
    }],
  },
...

postcss.config.js

...
const assets = require('postcss-assets'),
  autoprefixer = require('autoprefixer'),
  cssnano = require('cssnano'),
  inlineSVG = require('postcss-inline-svg'), 
  mqpacker = require('css-mqpacker');

const paths = require('./config/paths'),
  dev = process.env.NODE_ENV === 'development';

module.exports = {
  plugins: [
    assets({
      cacheBuster: true,
      loadPaths: [
        paths.images.main
      ]
    }),
    autoprefixer({
      browsers: 'last 2 versions'
    }),
    inlineSVG({
      path: paths.images.main
    }),
    mqpacker
  ].concat(dev ? [] : [
    cssnano
  ])
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions