"Webpack Var Injection" injects the wrong values

时间:2017-04-09 23:26:29

标签: javascript node.js webpack webpack-2

I see this in the console:

/* 469 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */ (function(global, console) {

'use strict';

//core

var path = __webpack_require__(20);
var assert = __webpack_require__(5);
var fs = __webpack_require__(30);
var util = __webpack_require__(1);

//npm
var colors = __webpack_require__(9);

//project
var sumanUtils = __webpack_require__(13);
var constants = __webpack_require__(10);

////////////////////////////////////////////////////////////////////////////////////

var loaded;

module.exports = function loadSharedObjects(pathObj, projectRoot) {

  if (loaded) {
    return loaded;
  }

  if (global.sumanOpts.init) {
    return loaded = {};
  }

as you can see, it's wrapping my code, and injecting both global and console...however, I don't really want Webpack to inject these variables, because apparently Webpack is injecting the wrong values for these.

How can I get Webpack to use

__webpack_require__ 

to source global and console?

The exact problem is that global.sumanOpts is undefined, and so I get an error saying that it cannot read property "init" of undefined. And that's why I am fairly certain that Webpack is not injecting the right value for global.

0 个答案:

没有答案