简体   繁体   English

我收到错误消息“找不到模块‘react’的声明文件”

[英]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.

相关问题 在反应中找不到模块错误的声明文件 - Could not find a declaration file for module error in react 得到错误:找不到模块'react-bootstrap-modal'的声明文件。在反应中 - getting error : Could not find a declaration file for module 'react-bootstrap-modal'. in react js 打字稿错误:找不到模块“react-dnd”的声明文件 - Typescript Error: Could not find a declaration file for module 'react-dnd' 错误:“无法找到模块'react-search-input'的声明文件” - Error: “Could not find a declaration file for module 'react-search-input'” 找不到模块“react”的声明文件 - Could not find a declaration file for module 'react' 在 React Js 中找不到模块的声明文件 - Could not find a declaration file for module in React Js React找不到模块'react-vis'的声明文件 - React Could not find a declaration file for module 'react-vis' 如何修复 - 找不到模块“@okta/okta-react”的声明文件 - 错误? - How to fix - Could not find a declaration file for module '@okta/okta-react' - error? 找不到模块“ react-hover”的声明文件 - Could not find a declaration file for module 'react-hover' 找不到模块'react-native-foo-package'的声明文件 - Could not find a declaration file for module 'react-native-foo-package'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM