[英]I want to ask when I import prop type an error occurred
I am doing the basic react app and prop type error has occurred in my application我正在做基本的反应应用程序,并且我的应用程序中发生了道具类型错误
./src/component/Navbar.js Cannot find file: 'index.js' does not match the corresponding name on disk: '.\node_modules\Prop-types\prop-types'. ./src/component/Navbar.js 找不到文件:“index.js”与磁盘上的相应名称不匹配:“.\node_modules\Prop-types\prop-types”。
import React from "react";
import PropTypes from 'Prop-types';
export default function Navbar(props) {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<div className="container-fluid">
<a className="navbar-brand" href="/">{props.title}</a>
<button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav me-auto mb-2 mb-lg-0">
<li className="nav-item">
<a className="nav-link active" aria-current="page" href="/">Home</a>
</li>
<li className="nav-item">
<a className="nav-link" href="/">{props.AboutText}</a>
</li>
</ul>
<form className="d-flex">
<input className="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
<button className="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
)
}
Navbar.propTypes = {
title: PropTypes.string,
aboutText: PropTypes.string
}
Navbar.defaultProps = {
title: 'Set title here',
aboutText: ''
};
The name of your import is slightly wrong.您的导入名称略有错误。 Javascript imports are case sensitive, so it should be following. Javascript 导入区分大小写,因此应该遵循。
import PropTypes from 'prop-types';
Notice the case of prop-types
.注意prop-types
的情况。
Also ensure prop-types
is present in your package.json
as a dependency already.还要确保您的package.json
中已经存在prop-types
作为依赖项。 Refer the installation guide for reference.请参阅安装指南以供参考。
Looks like you are importing prop-types
incorrectly.看起来您导入prop-types
不正确。 p
should be in lower case in prop-types
. p
在prop-types
中应该小写。 Please update your import as:请将您的导入更新为:
import PropTypes from "prop-types";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.