reactjs - Index.js 文件中的文件夹结构,未找到模块错误
问题描述
index.js
导入功能组件文件时如何在文件中写入文件夹目录结构。
下面是带有错误的代码。我的文件夹目录结构是这样的。那么如何在我的代码或index.js
文件中访问文件的导入和导出。
文件夹目录结构 -
E:\reactapp\AvatarDemo\my-app
错误
Failed to compile.
./src/index.js
Module not found: Can't resolve '.Avatar' in 'E:\reactapp\AvatarDemo\my-app\src'
Failed to compile
./src/index.js
Module not found: Can't resolve '.Avatar' in 'E:\reactapp\AvatarDemo\my-app\src'
This error occurred during the build time and cannot be dismissed.
功能组件文件
import React from 'react';
const Avatar = () =>{
<>
return
<h1>Hello Welcome to the world of Functional Components</h1>
<p>Naffy Kausar</p>
</>
}
export default Avatar;
//Index.js File
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
//import App from './App';
import Avatar from './Avatar';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<Avatar/>,document.getElementById("root"));
serviceWorker.unregister();
解决方案
尝试Avatar
像下面这样编写组件
import React from 'react';
const Avatar = () => (
<>
<h1>Hello Welcome to the world of Functional Components</h1>
<p>Naffy Kausar</p>
</>
)
推荐阅读
- arm - 用于高速微控制器测试台控制器/数据采集器的系统架构
- azure - 从 Azure DevOps 设置应用服务连接字符串
- c# - 等待 for 循环完成
- python - 更新烧瓶中的搜索数据后保持在同一页面上
- r - 绘制免疫表型图:暗示不同数量 rof 行错误的参数
- node.js - NodeJs POST 请求 ER_DATA_TOO_LONG
- javascript - 我怎样才能得到这个对象的值?
- python-3.x - Python 中的 Minimax AI
- mongodb - 如何使用`$cond`对多个条件进行分组
- kubernetes - Kubectl 等待 statefulset 的一个 pod 就绪?