我正在尝试使用 TypeScript 创建一个反应应用程序。我做了 yarn create react-app (name) --use-pnp --typescript。
TS linter 一直说找不到模块'react'.ts(2307) 我已经尝试过 yarn add @types/react、yarn add、重新启动 VScode 等。
import React, { Component } from 'react';
import './App.css';
interface IAppState {
}
interface IAppProps {
}
class App extends React.Component<IAppProps, IAppState> {
constructor(props: IAppState) {
super(props);
this.state = {
};
}
render() {
return (
<div className='App'>
<h1>Image classification with ML5.js</h1>
</div>
);
}
}
export default App;
我的 package.json
{
"name": "image-recognition",
"version": "0.1.0",
"private": true,
"installConfig": {
"pnp": true
},
"dependencies": {
"@types/jest": "24.0.13",
"@types/node": "12.0.2",
"@types/react": "^16.8.17",
"@types/react-dom": "^16.8.4",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"typescript": "3.4.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
我的 tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}
我尝试过 yarn add @types/react、yarn add、重启 VScode 等。