我使用React with Webpack-Dev-Server进行本地开发。
我不时会收到以下错误:“react_devtools_backend.js:6 [WDS]编译时发生错误。无法重新载入。”
发生错误后,浏览器上不会更新任何程式码变更。
package.json:
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@material-ui/core": "^4.10.0",
"babel-loader": "^8.1.0",
"css-loader": "^3.5.3",
"file-loader": "^6.0.0",
"lodash": "^4.17.15",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"style-loader": "^1.2.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0"}
"dependencies": {
"@material-ui/styles": "^4.9.14",
"clsx": "^1.1.0"}
webpack.config.js:
module.exports = {
mode: "development",
entry: "./src/main.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["@babel/plugin-transform-runtime"],
},
},
},
{
test: /\.css$/,
exclude: /node_modules/,
loader: ["style-loader", "css-loader"],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: "file-loader",
},
],
},
],
},
devServer: {
contentBase: path.join(__dirname, "dist"),
},
};
1条答案
按热度按时间pqwbnv8z1#
此问题似乎发生在eslint-loader中,其中热模块替换与
emitWarning: false
(默认值)沿着使用:这是我如何修复它(只是添加了
emitWarning
选项,并设置为true):请访问:https://github.com/webpack-contrib/eslint-loader#emitwarning-default-false