简体   繁体   中英

Webpack not recognising values defined by DefinePlugin

When webpack bundles and I launch the website, I get the following error:

*** process.env.ENV is not defined, assuming 'prod' env

However, if I log my process.env

Object {NODE_ENV: "development", ENV: "development", HOST: "localhost"}

My webpack configuration:

/*  Main */
const webpackConfig = {
  entry: [
    project.app.entry,
  ],
  output: {
    path: project.path.out,
    filename: 'bundle.js',
    publicPath: '/',
  },
  module: {
      rules: [{
        test: /\.js$/,
        include: project.path.app,
        exclude: /node_modules/,
        use: [
          { loader: 'babel-loader' },
          { loader: 'eslint-loader' },
        ],
      }],
  },
  plugins: [
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
        ENV: JSON.stringify(process.env.NODE_ENV),// Added because webpack bundle complains
        HOST: JSON.stringify(process.env.HOST),
      },
    }),
  ],
  devtool: DEV ? 'source-map' : false,
  resolve: {
    modules: ["src", "node_modules"],
    alias: {}
  }
};

Is this a bug in webpack, or am I missing something? Thank you.

Some people are having the same issue because of the Grammarly extension.

If you are using it, disable it and the error will be gone.


Related:

How to define process.env.ENV in create-react-app?

*** process.env.ENV is not defined, assuming 'prod' env

https://github.com/facebookincubator/create-react-app/issues/2722

It seems to be caused by the HotModuleReplacementPlugin for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM