webpack 警告 - DefinePlugin 中的警告 'process.env.NODE_ENV' 的值冲突 [英] webpack warning - WARNING in DefinePlugin Conflicting values for 'process.env.NODE_ENV'

查看:1888
本文介绍了webpack 警告 - DefinePlugin 中的警告 'process.env.NODE_ENV' 的值冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行开发模式时,我在标题中收到警告.该脚本曾经在早期网站上运行良好,但现在我总是收到此警告.

I'm getting the warning in the title when I try to run development mode. This script used to work fine for an earlier website but now I always get this warning.

这是我的 package.json:

This is my package.json:

{
  "name": "frontend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development --watch",
    "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.13.10",
    "@babel/preset-env": "^7.13.12",
    "@babel/preset-react": "^7.12.13",
    "babel-loader": "^8.2.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "webpack": "^5.27.2",
    "webpack-cli": "^4.5.0"
  },
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@material-ui/core": "^4.11.3",
    "@material-ui/icons": "^4.11.2",
    "react-router-dom": "^5.2.0"
  }
}

还有我的 webpack.config.js:

And my webpack.config.js:

const path = require("path");
const webpack = require("webpack");

module.exports = {
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "./static/frontend"),
    filename: "[name].js",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        },
      },
    ],
  },
  optimization: {
    minimize: true,
  },
  plugins: [
    new webpack.DefinePlugin({
      "process.env": {
        // This has effect on the react lib size
        NODE_ENV: JSON.stringify("production"),
      },
    }),
  ],
};

我到处搜索,但找不到与此警告类似的内容.

I've searched around everywhere but couldn't find anything similar to this warning.

推荐答案

感谢大家的帮助,非常感谢!

Thanks for helping everyone, very much appreciated!

我最终替换了生产"与发展"在 webpack.config 的以下片段中:

I ended up replacing "production" with "development" in the following snippet of the webpack.config:

plugins: [
    new webpack.DefinePlugin({
      "process.env": {
        // This has effect on the react lib size
        NODE_ENV: JSON.stringify("development"),
      },
    }),
  ]

它消除了警告,但我想知道这有什么影响.

It got rid of the warning but I'm wondering what impact this has.

这篇关于webpack 警告 - DefinePlugin 中的警告 'process.env.NODE_ENV' 的值冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆