gpt4 book ai didi

typescript 和 HMR 不工作

转载 作者:搜寻专家 更新时间:2023-10-30 21:20:20 28 4
gpt4 key购买 nike

我有使用 Typescript、ReactJS 和 Webpack 构建的前端应用程序。
我正在尝试启用 HMR。
这些是启动脚本

"build": "NODE_ENV=production $(npm bin)/webpack --watch",
"dev": "$(npm bin)/nodemon --exec \"$(npm bin)/ts-node\" ./server/server.ts || npm run build",

这是我的 ts-loader

{ test: /\.tsx?$/, loader: 'awesome-typescript-loader' }

还有我的开发服务器配置

if (NODE_ENV === 'development') {
let webpack = require('webpack')
const webpackConfig = require('../webpack.config')
const compiler = webpack(webpackConfig)

app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true, publicPath: webpackConfig.output.publicPath
}))
app.use(require('webpack-hot-middleware')(compiler))
}

我无法克服这个错误

[HMR] The following modules couldn't be hot updated: (Full reload needed)
This is usually because the modules which have changed (and their parents) do not know how to hot reload themselves. See http://webpack.github.io/docs/hot-module-replacement-with-webpack.html for more details.

最佳答案

有同样的问题,并通过添加 react-hot-loader 修复它,可以使用 npm install --save-dev react-hot-loader 安装.

你的配置应该是这样的:

{ test:/\.tsx?$/, loaders:['react-hot', 'awesome-typescript-loader'] }

关于 typescript 和 HMR 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37734983/

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