gpt4 book ai didi

typescript - HtmlWebpackPlugin 不适用于 typescript 应用程序

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

这是我的 webpack.config.js

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, "build"),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader"
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./index.html"
})
]
}

这是我的 package.json

{
"name": "react-ts-todo",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "webpack-dev-server --mode development"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"devDependencies": {
"@types/react": "^16.1.0",
"@types/react-dom": "^16.0.4",
"awesome-typescript-loader": "^4.0.1",
"html-webpack-plugin": "^3.1.0",
"typescript": "^2.8.1",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
}
}

我可以使用 nom start 轻松启动我的 webpack 服务器,但是当我更改我的文件并尝试刷新时。我的 webpack 开发服务器因错误而崩溃

TypeError: Cannot read property '_tsInstances' of undefined
at resolveInstance (/Users/user1/IdeaProjects/react-ts-todo/node_modules/awesome-typescript-loader/src/instance.ts:73:16)
at /Users/user1/IdeaProjects/react-ts-todo/node_modules/awesome-typescript-loader/src/instance.ts:368:20
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/user1/IdeaProjects/react-ts-todo/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:25:1)
at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/Users/user1/IdeaProjects/react-ts-todo/node_modules/tapable/lib/Hook.js:35:21)
at Watching._go (/Users/user1/IdeaProjects/react-ts-todo/node_modules/webpack/lib/Watching.js:40:32)
at Watching._invalidate (/Users/user1/IdeaProjects/react-ts-todo/node_modules/webpack/lib/Watching.js:164:9)
at watcher.compiler.watchFileSystem.watch (/Users/user1/IdeaProjects/react-ts-todo/node_modules/webpack/lib/Watching.js:135:10)
at Watchpack.watcher.once (/Users/user1/IdeaProjects/react-ts-todo/node_modules/webpack/lib/node/NodeWatchFileSystem.js:43:4)

我用谷歌搜索并找到了这个

https://github.com/s-panferov/awesome-typescript-loader/issues/541

但这对我来说没有明确可行的解决方案。

最佳答案

好的。我找到了答案 here .我们需要将很棒的 typescript 加载器升级到

"awesome-typescript-loader": "^5.0.0-1"

以下 package.json 工作正常。

{
"name": "react-ts-todo",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "webpack-dev-server --mode development"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"devDependencies": {
"@types/react": "^16.1.0",
"@types/react-dom": "^16.0.4",
"awesome-typescript-loader": "^5.0.0-1",
"html-webpack-plugin": "^3.1.0",
"typescript": "^2.8.1",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
}
}

关于typescript - HtmlWebpackPlugin 不适用于 typescript 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49599873/

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