2017-05-06 180 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$/, ... 我曾评论它

相关问题