wepack4配置webpack-dev-server报错

发布于 2022-09-07 11:37:15 字数 2226 浏览 15 评论 0

const validateSchema = process.webpackModule.validateSchema;
^TypeError: Cannot read property 'validateSchema' of undefined
at Object.<anonymous> (E:wampwamp64wwwKaoyannode_moduleswebpack-clibinconvert-argv.js:7:46)
//webpackconfig.js
const webpack = require("webpack");
const path = require("path");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "babel-loader"
      },
      {
        test: /\.(scss|css)$/,

        use: [
          {
            loader: "style-loader"
          },
          {
            loader: "css-loader"
          },
          {
            loader: "sass-loader"
          }
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(["dist"]),
    new UglifyJSPlugin(),
    new HtmlWebpackPlugin({ title: "kaoyan", template: "./index.html" })
  ],
  entry: "./src/index",

  output: {
    filename: "[name].[chunkhash].js",
    chunkFilename: "[name].[chunkhash].js",
    path: path.resolve(__dirname, "dist")
  }
};
{
  "name": "kaoyan",
  "version": "1.0.0",
  "description": "kaoyan app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server --mode=development --open"
  },
  "author": "Renkosky",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "clean-webpack-plugin": "^0.1.19",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.10.2",
    "webpack-cli": "^3.0.0",
    "webpack-dev-server": "^3.1.4"
  },
  "dependencies": {
    "css-loader": "^0.28.11",
    "node-sass": "^4.9.0",
    "react": "^16.4.0",
    "react-dom": "^16.4.0",
    "sass-loader": "^7.0.2",
    "style-loader": "^0.21.0",
    "uglifyjs-webpack-plugin": "^1.2.5"
  }
}

我记得配置中不修改dev-server行为的话就不用添加dev-server的相关配置,但不知怎么就是报错,如果有知道的求告知,感激不尽!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不一样的天空 2022-09-14 11:37:15

从报错来看的话,是process的问题,dev-server有一个配置参数是process,可以查查api有讲解

萌化 2022-09-14 11:37:15

开发环境不能使用chunkhash,你把输出文件名改一下应该就可以了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文