[英]I'm getting an error of "Could not find a declaration file for module 'react'"
I'm trying to import React from 'react' and getting an error..我正在尝试从“react”导入 React 并出现错误..
The setup I'm using was created with the standard npx create-react-app.我使用的设置是使用标准 npx create-react-app 创建的。
The error I'm seeing is from VS Code.我看到的错误来自 VS Code。
import React from 'react';从“反应”导入反应;
Could not find a declaration file for module 'react'.找不到模块“react”的声明文件。 '/home/darryl/dev/learn-react/node_modules/react/index.js' implicitly has an 'any' type.
'/home/darryl/dev/learn-react/node_modules/react/index.js' 隐式有一个 'any' 类型。 Try
npm install @types/react
if it exists or add a new declaration (.d.ts) file containing `declare m如果存在,请尝试
npm install @types/react
或添加包含 `declare m 的新声明 (.d.ts) 文件
I'd expect to not receive this error and for my app to load in the browser.我希望不会收到此错误,并且我的应用程序可以在浏览器中加载。
I haven't tried the suggest fix yet 'npm install @types/react' as I should not be receiving this error anyway and I was hoping to gain further understanding of why I am seeing this before making changes.我还没有尝试过建议修复“npm install @types/react”,因为无论如何我都不应该收到这个错误,我希望在进行更改之前进一步了解为什么我会看到这个错误。
Thanks谢谢
Running the suggested fix 'npm install @types/react' seems to fix the issue. 运行建议的修复程序'npm install @ types / react'似乎可以解决此问题。 But this seems to be an issue with the create-react-app installer then?
但这似乎与create-react-app安装程序有关吗?
It seems to be an issue with the create-react-app.这似乎是 create-react-app 的问题。 Try installing all the dependencies again running
npm install
尝试再次运行
npm install
安装所有依赖项
尝试npm install --save react
。
Is react well listed in "dependencies" in your package.json ? 在package.json的“ dependencies”中是否很好地列出了react?
Have you try to import it with require (Vanilla Style instead of ES6)? 您是否尝试使用require(Vanilla Style而不是ES6)导入它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.