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?
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.
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.
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.
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', }), ] }
You need to add a plugin to define your env (in webpack config):
plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('development') }) ],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With