Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack: Bundle.js - Uncaught ReferenceError: process is not defined

Here's my webpack.config.js

"use strict";  module.exports = {     entry: ['./main.js'],     output: { path: __dirname, filename: 'bundle.js' },     module: {         loaders: [             {                 test: /.js?$/,                 loader: 'babel-loader',                 exclude: /node_modules/,                 query: {                     presets: ['es2015', 'react']                 }             },             {test: /\.json$/, loader: "json"},         ]     },     externals: {         React: 'react',     },     target: "node", }; 

And Main.js

import React from 'react'; import ReactDOM from 'react-dom'; import {Table, Column, Cell} from 'fixed-data-table'; import Chart from 'chartjs'; import jQuery from 'jquery'; import vis from 'vis'; import babel from 'babel-core'; 

The Bundle.js is inserted in my Index.html. The browser then gives the error:

Uncaught ReferenceError: process is not defined     at Object.measureMethods (bundle.js:1297)     at Object.<anonymous> (bundle.js:530)     at __webpack_require__ (bundle.js:20)     at Object.<anonymous> (bundle.js:288)     at __webpack_require__ (bundle.js:20)     at Object.<anonymous> (bundle.js:158)     at __webpack_require__ (bundle.js:20)     at Object.<anonymous> (bundle.js:110)     at __webpack_require__ (bundle.js:20)     at Object.<anonymous> (bundle.js:90) 

What should I change in the webpack.config.js to make this error go away?

like image 479
cbll Avatar asked Dec 28 '16 09:12

cbll


People also ask

How do you fix ReferenceError process is not defined?

To solve the "Uncaught ReferenceError: process is not defined" in React, open your terminal in your project's root directory and update the version of your react-scripts package by running npm install react-scripts@latest and re-install your dependencies if necessary.

Where is webpack config JS?

The webpack configuration file webpack. config. js is the file that contains all the configuration, plugins, loaders, etc. to build the JavaScript part of the NativeScript application. The file is located at the root of the NativeScript application.

What is a webpack plugin?

A webpack plugin is a JavaScript object that has an apply method. This apply method is called by the webpack compiler, giving access to the entire compilation lifecycle.


2 Answers

Update October 2020:

For webpack 5, you can reference process/browser from the appropriate plugins part of webpack.config.js

// webpack needs to be explicitly required const webpack = require('webpack')  module.exports = {  /* ... rest of the config here ... */    plugins: [     // fix "process is not defined" error:     // (do "npm install process" before running the build)     new webpack.ProvidePlugin({       process: 'process/browser',     }),   ] } 
like image 112
Fergie Avatar answered Sep 23 '22 02:09

Fergie


You need to add a plugin to define your env (in webpack config):

   plugins: [         new webpack.DefinePlugin({             'process.env.NODE_ENV': JSON.stringify('development')         })     ], 
like image 45
Kinnza Avatar answered Sep 24 '22 02:09

Kinnza