首页 > undefined is not an object (evaluating 'process.env.NODE_ENV')

undefined is not an object (evaluating 'process.env.NODE_ENV')

启动npm环境成功,但是浏览器上报错:

TypeError: undefined is not an object (evaluating 'process.env.NODE_ENV')
keyMirror - keyMirror.js:38

查看:keyMirror:

/**
 * Constructs an enumeration with keys equal to their value.
 *
 * For example:
 *
 *   var COLORS = keyMirror({blue: null, red: null});
 *   var myColor = COLORS.blue;
 *   var isColorValid = !!COLORS[myColor];
 *
 * The last line could not be performed if the values of the generated enum were
 * not equal to their keys.
 *
 *   Input:  {key1: val1, key2: val2}
 *   Output: {key1: key1, key2: key2}
 *
 * @param {object} obj
 * @return {object}
 */
var keyMirror = function(obj) {
  var ret = {};
  var key;
  ("production" !== process.env.NODE_ENV ? invariant(
    obj instanceof Object && !Array.isArray(obj),
    'keyMirror(...): Argument must be an object.'
  ) : invariant(obj instanceof Object && !Array.isArray(obj)));
  for (key in obj) {
    if (!obj.hasOwnProperty(key)) {
      continue;
    }
    ret[key] = key;
  }
  return ret;
};

module.exports = keyMirror;

后来发现是在webpack里配置的问题:

loaders: [{
            test: /\.jsx?$/, 
            loaders: ['react-hot', 'babel'],
            include: path.resolve(ROOT_PATH, 'app/src')
            }
          ...
          ]

加上include: path.resolve(ROOT_PATH, 'app/src')限制解析范围,就好了。
推测也可以提速。

【热门文章】
【热门文章】