2017-06-27 94 views
1

我正在使用webpack和webpack-dev-server重建MEAN堆栈网站的本地开发版本。我使用下面的脚本来运行的WebPack-dev的服务器:找不到模块“。” - webpack

(内的package.json):

"dev": "NODE_ENV=development webpack-dev-server --config webpack/webpack.dev.js --content-base src/app/ --inline"

webpack.dev.js:

path = require('path'); 
 
commonConfig = require('./webpack.js'); 
 

 
output = { 
 
    path: path.resolve(__dirname, 'build'), 
 
    publicPath: 'http://localhost:8080/build/', 
 
    filename: 'heliotrope.js' 
 
}; 
 

 
module.exports = Object.assign(commonConfig, { 
 
    output: output, 
 
    devtool: 'source-map', 
 
    plugins: commonConfig.plugins, 
 
    externals: ['ws'] 
 
});

该网站建立和服务良好,但然后我得到这个错误,这几乎是最少的信息以往的事情:

error msg

望着JavaScript的编译文件,heliotrope.js,看起来这可能有些事情要使用WebSockets,但我不知道,因为该模块实际上不是命名!

/***/ }), 
 
/* 288 */ 
 
/***/ (function(module, exports, __webpack_require__) { 
 

 
"use strict"; 
 
/* WEBPACK VAR INJECTION */(function(__webpack_provided_process_dot_env) { 
 

 
var utils = __webpack_require__(12) 
 
    , urlUtils = __webpack_require__(8) 
 
    , inherits = __webpack_require__(0) 
 
    , EventEmitter = __webpack_require__(6).EventEmitter 
 
    , WebsocketDriver = __webpack_require__(279) 
 
    ; 
 

 
var debug = function() {}; 
 
if (__webpack_provided_process_dot_env.NODE_ENV !== 'production') { 
 
    debug = __webpack_require__(4)('sockjs-client:websocket'); 
 
} 
 

 
function WebSocketTransport(transUrl, ignore, options) { 
 
    if (!WebSocketTransport.enabled()) { 
 
    throw new Error('Transport created when disabled'); 
 
    } 
 

 
    EventEmitter.call(this); 
 
    debug('constructor', transUrl); 
 

 
    var self = this; 
 
    var url = urlUtils.addPath(transUrl, '/websocket'); 
 
    if (url.slice(0, 5) === 'https') { 
 
    url = 'wss' + url.slice(5); 
 
    } else { 
 
    url = 'ws' + url.slice(4); 
 
    } 
 
    this.url = url; 
 

 
    this.ws = new WebsocketDriver(this.url, [], options); 
 
    this.ws.onmessage = function(e) { 
 
    debug('message event', e.data); 
 
    self.emit('message', e.data); 
 
    }; 
 
    // Firefox has an interesting bug. If a websocket connection is 
 
    // created after onunload, it stays alive even when user 
 
    // navigates away from the page. In such situation let's lie - 
 
    // let's not open the ws connection at all. See: 
 
    // https://github.com/sockjs/sockjs-client/issues/28 
 
    // https://bugzilla.mozilla.org/show_bug.cgi?id=696085 
 
    this.unloadRef = utils.unloadAdd(function() { 
 
    debug('unload'); 
 
    self.ws.close(); 
 
    }); 
 
    this.ws.onclose = function(e) { 
 
    debug('close event', e.code, e.reason); 
 
    self.emit('close', e.code, e.reason); 
 
    self._cleanup(); 
 
    }; 
 
    this.ws.onerror = function(e) { 
 
    debug('error event', e); 
 
    self.emit('close', 1006, 'WebSocket connection broken'); 
 
    self._cleanup(); 
 
    }; 
 
} 
 

 
inherits(WebSocketTransport, EventEmitter); 
 

 
WebSocketTransport.prototype.send = function(data) { 
 
    var msg = '[' + data + ']'; 
 
    debug('send', msg); 
 
    this.ws.send(msg); 
 
}; 
 

 
WebSocketTransport.prototype.close = function() { 
 
    debug('close'); 
 
    var ws = this.ws; 
 
    this._cleanup(); 
 
    if (ws) { 
 
    ws.close(); 
 
    } 
 
}; 
 

 
WebSocketTransport.prototype._cleanup = function() { 
 
    debug('_cleanup'); 
 
    var ws = this.ws; 
 
    if (ws) { 
 
    ws.onmessage = ws.onclose = ws.onerror = null; 
 
    } 
 
    utils.unloadDel(this.unloadRef); 
 
    this.unloadRef = this.ws = null; 
 
    this.removeAllListeners(); 
 
}; 
 

 
WebSocketTransport.enabled = function() { 
 
    debug('enabled'); 
 
    return !!WebsocketDriver; 
 
}; 
 
WebSocketTransport.transportName = 'websocket'; 
 

 
// In theory, ws should require 1 round trip. But in chrome, this is 
 
// not very stable over SSL. Most likely a ws connection requires a 
 
// separate SSL connection, in which case 2 round trips are an 
 
// absolute minumum. 
 
WebSocketTransport.roundTrips = 2; 
 

 
module.exports = WebSocketTransport; 
 

 
/* WEBPACK VAR INJECTION */}.call(exports, !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())))

任何帮助将不胜感激,我很卡住:)

回答

0

的问题是在我的主要webpack.config文件,我在那里用ProvidePlugin提供NODE_ENV变量:

new webpack.ProvidePlugin({ 
    'process.env': { 
    'NODE_ENV': process.env.NODE_ENV 
    } 
}) 

相反,我现在用DefinePlugin像这样:

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