Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "Invariant Violation: webpackConfig must be a plain object" #56

Closed
codeuniquely opened this issue Oct 14, 2016 · 2 comments
Closed

Comments

@codeuniquely
Copy link

I have basically tried to set up my project in line with configuration in the thread #19

But I'm getting this error when I try to run mocha-webpack

File [/Users/steve/project/webpack.test.config.js] ignored, nothing could be mapped
/Users/steve/project/node_modules/invariant/invariant.js:49
    throw error;
    ^

Invariant Violation: webpackConfig must be a plain object
    at invariant (/Users/steve/project/node_modules/invariant/invariant.js:42:15)
    at createCompiler (/Users/steve/Project/node_modules/mocha-webpack/lib/webpack/createCompiler.js:32:27)
    at build (/Users/steve/project/node_modules/mocha-webpack/lib/webpack/build.js:19:47)
    at run (/Users/steve/projects/node_modules/mocha-webpack/lib/cli/runner.js:49:23)
    at /Users/steve/project/node_modules/mocha-webpack/lib/cli/index.js:59:21
    at /Users/steve/project/node_modules/mocha-webpack/lib/cli/prepareWebpack.js:188:11
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Function.Module.runMain (module.js:577:11)
    at Function.runMain (/Users/steve/.node-spawn-wrap-5982-492946983996/node:40:10)
    at Object.<anonymous> (/Users/steve/project/node_modules/nyc/bin/wrap.js:22:4)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at Object.<anonymous> (/Users/steve/.node-spawn-wrap-5982-492946983996/node:140:8)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
    at run (bootstrap_node.js:352:7)
    at startup (bootstrap_node.js:144:9)
    at bootstrap_node.js:467:3

in webpack.config.test.js

var webpack         = require('webpack');
var path            = require('path');
var nodeExternals   = require('webpack-node-externals');

// Define the environment
var env             = 'test';

// ==============================
//  Paths
// ==============================
var rootPath        = path.resolve( __dirname );
var nodeModulesPath = path.resolve( __dirname, 'node_modules');
var buildPath       = path.resolve( __dirname, 'build');
var srcPath         = path.resolve( __dirname, 'src' );
var serverPath      = path.resolve( srcPath, 'server' );
var libPath         = path.resolve( srcPath, 'lib' );
var modelPath       = path.resolve( srcPath, 'models' );
var routePath       = path.resolve( srcPath, 'routes' );

// ==============================
//  CommonJS wrap all Externals
// ==============================
var extNodeModules  = nodeExternals();

// ==============================
//  Plugins
// ==============================
var plugins = [

  new webpack.DefinePlugin({
    'process.env': {
      ENV: JSON.stringify(env),
      NODE_ENV: JSON.stringify(env)
    }
  }),

  new webpack.NoErrorsPlugin()
];

// ==============================
//  Pre-loaders
// ==============================
var preLoaders = [
  {
    test: /\.js$/i,
    loaders: ['babel'],
    exclude: [
      nodeModulesPath       // skip anything in node_modules
    ]
  },
  {
    test: /\.js$/i,
    include: srcPath,
    exclude: [
      nodeModulesPath,      // skip anything in node_modules
      /\.spec\.js$/         // skip instrumentaion on *.spec.js files
    ],
    loader: 'istanbul-instrumenter'
  }
];

// ==============================
//  Loaders
// ==============================
var loaders = [
  { test: /\.json$/i, loader: 'json' }
];

module.exports = {
  resolve: {
    alias:{
      root: rootPath,
      server: serverPath,
      src: srcPath,
      lib: libPath,
      models: modelPath,
      routes: routePath,
      node: nodeModulesPath
    },
    extensions: ['', '.js', '.json' ]
  },
  target: 'node',
  externals: [ extNodeModules ],
  plugins: plugins,
  module: {
    preLoaders: preLoaders,
    loaders: loaders
  }
};

in package.json

  "scripts": {
     "test": "NODE_ENV=test BABEL_ENV=test nyc mocha-webpack",
  },
  "nyc": {
    "reporter": [
      "lcov",
      "text-summary"
    ],
    "exclude": [
      "node_modules",
      "test"
    ]
  },
  "devDependencies": {
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.5",
    "babel-plugin-istanbul": "^2.0.1",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-stage-0": "^6.5.0",
    "istanbul-instrumenter-loader": "^1.0.0",
    "json-loader": "^0.5.3",
    "mocha": "^3.0.2",
    "mocha-webpack": "^0.7.0",
    "nyc": "^8.3.1",
    "webpack": "^1.13.2"
  }

in mocha.options.json

--require babel-core/register
--colors
--reporter spec
--ui bdd
--webpack-config webpack.test.config.js
src/**/*.spec.js

in babel.rc

{
  "presets": ["es2015", "stage-0"],
  "env": {
    "test": {
      "plugins": ["istanbul"]
    }
  }
}
@codeuniquely
Copy link
Author

codeuniquely commented Oct 14, 2016

after a bit of debugging

createCompiler.js

function createCompiler(webpackConfig) {
 (0, _invariant2.default)(_lodash2.default.isPlainObject(webpackConfig), 'webpackConfig must be a plain object');
}

which makes a call into lodash.isPlainObject()

function isPlainObject(value) {
  if (!isObjectLike(value) || objectToString.call(value) != objectTag) {
    return false;
  }
  var proto = getPrototype(value);
  if (proto === null) {
    return true;
  }
  var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  return (typeof Ctor == 'function' &&
    Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
}

when I look at the variables
objectToString.call(value) => "[object Array]"

whereas objectTag is expecting "[object Object]"

the contents of value are

Array[1]
  context:"/Users/steve/Projects/CallMeBack/procheck-api/.tmp/mocha-webpack"
  entry:"./1a060d55bfc9cb75db0c27c8d4597b28-entry.js"

  output:Object
  plugins:Array[2]
    [0]:WebpackInfoPlugin
    [1]:ContextReplacementPlugin
  Object[0]
    babel:Object
    externals:Array[1]
      [0]:function (context, request, callback) { … }
    module:Object
      loaders:Array[3]
      preLoaders:Array[2]
    plugins:Array[2]
      [0]:DefinePlugin
      [1]:NoErrorsPlugin
    resolve:Object
      alias:Object
      extensions:Array[3]
        [0]:""
        [1]:".js"
        [2]:".json"
    target:"node"

Not really sure what to do here as I simply just pass a reference to the webpack config file and its the same format that I use for development / build and deployment

@codeuniquely
Copy link
Author

Worked it out:
I was bundling several parts UI, Proxy, BackEnd into an array and passing that back to webpack (more than one server is being build)

for testing I just pass each in turn builds[0] ... builds[3]

@zinserjan zinserjan mentioned this issue Dec 7, 2016
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant