2016-05-14 68 views
3

當我運行命令「webpack」 - everyting好,但是當我運行「webpack-dev-server -content-base src -inline -hot」 - 我得到錯誤。 可能是sytax錯誤,我打賭我找不到問題。問題與webpack.config.js

C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:72 
         var elements = request.replace(/^-?!+/, "").replace(/!!+/g, "!").split("!"); 
              ^

TypeError: Cannot read property 'replace' of undefined 
    at C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:72:26 
    at C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:28:4 
    at C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:159:3 
    at NormalModuleFactory.applyPluginsAsyncWaterfall (C:\wamp\www\react\node_modules\webpack\node_modules\tapable\lib\Tapable.js:75:69) 
    at NormalModuleFactory.create (C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:144:8) 
    at C:\wamp\www\react\node_modules\webpack\lib\Compilation.js:214:11 
    at C:\wamp\www\react\node_modules\webpack\node_modules\async\lib\async.js:181:20 
    at Object.async.forEachOf.async.eachOf (C:\wamp\www\react\node_modules\webpack\node_modules\async\lib\async.js:233:13) 
    at Object.async.forEach.async.each (C:\wamp\www\react\node_modules\webpack\node_modules\async\lib\async.js:209:22) 
    at Compilation.addModuleDependencies (C:\wamp\www\react\node_modules\webpack\lib\Compilation.js:185:8) 

我的配置:

var debug = process.env.NODE_ENV !== "production"; 
var webpack = require('webpack'); 

module.exports = { 
    context: __dirname+"/resources/assets/js", 
    devtool: debug ? "inline-sourcemap" : null, 
    entry: "./test.jsx", 
    module: { 
     loaders: [ 
      { 
       test: /\.jsx?$/, 
       exclude: /(node_modules|bower_components)/, 
       loader: 'babel-loader', 
       query: { 
        presets: ['react', 'es2015', 'stage-0'], 
        plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'] 
       } 
      } 
     ] 
    }, 
    output: { 
     path: __dirname + "/public/js", 
     filename: "scripts.min.js" 
    }, 
    plugins: debug ? [] : [ 
     new webpack.optimize.DedupePlugin(), 
     new webpack.optimize.OccurenceOrderPlugin(), 
     new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }) 
    ] 
}; 

目錄結構:

C:\wamp\www\react\public\js\ - output 
C:\wamp\www\react\resources\assets\js\ - srouce (ex. test.jsx) 
C:\wamp\www\react\node_modules\ - node modules 
C:\wamp\www\react\ - root directory (ex. webpack.config.js) 
+0

Please post your directory structure – Steffen

+0

沒有足夠的信息來說明任何結論。 –

+0

Steffen>更新了,請看看。 bebraw>你需要什麼樣的數據? – lolalola

回答

0

對我來說,當我用--inline

"webpack": "1.12.11" 
"webpack-dev-server": "1.16.2" 

只要我不出現此錯誤」試着用--in行,一切正常。

0

請確保您的webpack命令指向配置,我有這個問題,它變成因爲我沒有指向webpack配置。 例如 webpack-dev-server --config webpack/webpack.dev.config --inline