What is the current behavior?
Thrown the error Uncaught ReferenceError: require is not defined
If the current behavior is a bug, please provide the steps to reproduce.
Just running webpack command with the below config
/**
* Created by abdi.fakhruddin on 5/5/17.
*/
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: 'node',
// 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',
exclude: [
/node_modules/,
/\/src\/.*\/.*\/.*.test.js\//
],
}, {
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'
}
What is the expected behavior?
Build the project and run it with http-server
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
Node: 6.6.1
webpack: 2.5.0
OS: Mac OSX
Browser: chrome
**The error **
Uncaught ReferenceError: require is not defined
(anonymous) @ external "babel-polyfill":1
__webpack_require__ @ bootstrap 59b71a2…:19
(anonymous) @ client.js:5
__webpack_require__ @ bootstrap 59b71a2…:19
(anonymous) @ bootstrap 59b71a2…:39
(anonymous) @ bootstrap 59b71a2…:39
Yep the
externals
is fine in the tutorial, because it build for server. You built for client.@FakhruddinAbdi Have you been solved this issue,bro?