2017-05-06 550 views
1

我一直在爲一個項目工作約2個月,並使用webpack-dev-middlewareUncaught ReferenceError:require is not defined react + webpack

根據WDM文檔,它只是一個webpack的包裝器,並在內存中運行項目以啓用熱重載。

但現在當我試圖與webpack和相同的webpack.config.js構建和部署我得到Uncaught ReferenceError: require is not defined錯誤。

我已經搜索了很多,找不到正確的答案爲我的情況。

我真的很感激任何幫助:)。

我webpack.config.js

var ExtractTextPlugin = require('extract-text-webpack-plugin'); 
var path = require('path'); 
var autoprefixer = require('autoprefixer'); 
const webpack = require('webpack'); 
var fs = require('fs') 

module.exports = { 

    entry: './src/client.js', 

    output: { 
    path: path.join(__dirname, 'public'), 
    filename: 'bundle.js' 
    }, 

    target: 'web', 

    // keep node_module paths out of the bundle 
    externals: fs.readdirSync(path.resolve(__dirname, 'node_modules')).concat([ 
    'react-dom/server', 'react/addons', 
    ]).reduce(function (ext, mod) { 
    ext[mod] = 'commonjs ' + mod 
    return ext 
    }, {}), 

    node: { 
    __filename: true, 
    __dirname: true 
    }, 

    plugins: [ 
    new ExtractTextPlugin('styles.css'), 
    ], 

    module: { 
    loaders: [ 
     { 
     test: /\.js$/, 
     loader: 'babel-loader', 
     }, { 
     test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/, 
     loader: 'url-loader?limit=100000&name=/[hash].[ext]', 
     }, { 
     test: /\.scss$/, 
     loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']), 
     }, 
     { test: /\.json$/, loader: "json-loader"} 
    ], 
    }, 

    devtool: 'cheap-module-source-map' 

} 

我使用的WebPack版本:1.13.3地方。

+0

我沒有看到什麼明顯的錯誤,你在哪裏正是得到這個錯誤?當你建立你的項目,或者當你用瀏覽器打開它時? – Patrick

+0

當我構建時,它會成功完成構建 但是當我在瀏覽器中運行它時,我看到錯誤 –

回答

0

在我的情況的原因是: ... module: { noParse: /\.min\.js$/, ... 我曾評論它

相關問題