Here’s my webpack.config.js
JavaScript
x
24
24
1
"use strict";
2
3
module.exports = {
4
entry: ['./main.js'],
5
output: { path: __dirname, filename: 'bundle.js' },
6
module: {
7
loaders: [
8
{
9
test: /.js?$/,
10
loader: 'babel-loader',
11
exclude: /node_modules/,
12
query: {
13
presets: ['es2015', 'react']
14
}
15
},
16
{test: /.json$/, loader: "json"},
17
]
18
},
19
externals: {
20
React: 'react',
21
},
22
target: "node",
23
};
24
And Main.js
JavaScript
1
8
1
import React from 'react';
2
import ReactDOM from 'react-dom';
3
import {Table, Column, Cell} from 'fixed-data-table';
4
import Chart from 'chartjs';
5
import jQuery from 'jquery';
6
import vis from 'vis';
7
import babel from 'babel-core';
8
The Bundle.js is inserted in my Index.html. The browser then gives the error:
JavaScript
1
12
12
1
Uncaught ReferenceError: process is not defined
2
at Object.measureMethods (bundle.js:1297)
3
at Object.<anonymous> (bundle.js:530)
4
at __webpack_require__ (bundle.js:20)
5
at Object.<anonymous> (bundle.js:288)
6
at __webpack_require__ (bundle.js:20)
7
at Object.<anonymous> (bundle.js:158)
8
at __webpack_require__ (bundle.js:20)
9
at Object.<anonymous> (bundle.js:110)
10
at __webpack_require__ (bundle.js:20)
11
at Object.<anonymous> (bundle.js:90)
12
What should I change in the webpack.config.js to make this error go away?
Advertisement
Answer
You need to add a plugin to define your env (in webpack config):
JavaScript
1
6
1
plugins: [
2
new webpack.DefinePlugin({
3
'process.env.NODE_ENV': JSON.stringify('development')
4
})
5
],
6