gpt4 book ai didi

javascript - 无效的 HMR 消息错误 Webpack

转载 作者:IT老高 更新时间:2023-10-28 23:06:35 26 4
gpt4 key购买 nike

我从 Webpack 收到以下错误:

无效的 HMR 消息后跟一串非常详细的 JSON。

我真的找不到任何资源来更好地调试它。有什么建议吗?

Webpack console errors

如果有人能告诉我为什么在整个应用程序中使用 require 时找不到问题,那么奖金。

以下是一些细节:

  • 运行 Node/Babel
  • 使用 Webpack

NPM 依赖项:

  "dependencies": {
"babel-core": "^6.7.2",
"babel-polyfill": "^6.7.4",
"body-parser": "~1.12.0",
"cookie-parser": "~1.3.4",
"css-modules-require-hook": "^4.0.0",
"cuid": "^1.3.8",
"debug": "~2.1.1",
"express": "~4.12.2",
"fs": "0.0.2",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-redux": "^4.4.1",
"react-router": "^2.0.1",
"redux": "^3.3.1",
"serve-favicon": "~2.2.0",
"webpack": "^1.12.13"
},
"devDependencies": {
"babel-eslint": "^5.0.0",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-register": "^6.7.2",
"cross-env": "^1.0.7",
"css-modules-require-hook": "^4.0.0",
"eslint": "^2.6.0",
"redux-devtools": "^3.1.1",
"redux-devtools-dock-monitor": "^1.1.0",
"redux-devtools-log-monitor": "^1.0.4",
"webpack-dev-middleware": "^1.5.1",
"webpack-hot-middleware": "^2.10.0"
}

Webpack 配置:

var webpack = require('webpack');
var path = require('path');
var fs = require('fs');

var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});

module.exports = {
devtool: 'cheap-source-map',

entry: ['webpack-hot-middleware/client',
'./index.js',
],
target: 'node',
output: {
path: __dirname,
filename: 'bundle.js',
},

resolve: {
extensions: ['', '.js', '.jsx'],
},

module: {
loaders: [
{
test: /\.css$/,
loader: 'style!css?modules',
},
{
test: /\.jsx*$/,
exclude: [/node_modules/, /.+\.config.js/],
loader: 'babel',
query: {
presets: ['react-hmre'],
},
},
],
},

plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': {
CLIENT: JSON.stringify(true)
}
})
],

externals: nodeModules

};

最佳答案

将您的 targetnode 设置为 client.js 的 web

如果你正在捆绑一个服务器端的 React 应用,你可以添加到服务器文件的顶部:

require('css-modules-require-hook')({
generateScopedName: '[name]--[local]',
prepend: []
});

以便 SSR react 组件中所需的 css 文件工作。

关于javascript - 无效的 HMR 消息错误 Webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com