官方示例:https://www.tslang.cn/docs/handbook/react-&-webpack.html
输入Webpack出错:
One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no):
看样子是缺少webpack-cli,
全局安装,在cmd输入:npm install -g webpack-cli
再次输入Webpack,仍旧出错
ERROR in [at-loader] ./node_modules/@types/react/index.d.ts:427:23
TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
按照提示的内容,打开编写的tsconfig.json,修改target属性为es2015
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es2015",
"jsx": "react"
},
"include": [
"./src/**/*"
]
}
这时出了警告,但是试试打开index.html,正常了。