gpt4 book ai didi

reactjs - typescript :找不到模块 'react'

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

我不明白为什么找不到它。

$ cat tsconfig.json

{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"jsx": "react",
"types": [
"lodash",
"react",
"react-dom"
]
}
}

$ tree node_modules/@types

node_modules/@types/
├── lodash
│   ├── README.md
│   ├── index.d.ts
│   ├── package.json
│   └── types-metadata.json
├── react
│   ├── README.md
│   ├── index.d.ts
│   ├── package.json
│   └── types-metadata.json
└── react-dom
├── README.md
├── index.d.ts
├── package.json
├── server.d.ts
└── types-metadata.json

导入组件文件。

// src/components/component.tsx

import * as React from "react";

什么给了?

最佳答案

我遇到了同样的问题。你只需要安装@types:

npm i -D @types/react

关于reactjs - typescript :找不到模块 'react',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40899868/

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