简体   繁体   English

我想问当我导入道具类型时发生错误

[英]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 . pprop-types中应该小写。 Please update your import as:请将您的导入更新为:

import PropTypes from "prop-types";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想获取iframe的内容,但是发生了错误 - I want to get contents of iframe , but an error occurred 我想问一下getElementbyId - I want to ask about getElementbyId 我想问一下所有复选框/取消复选框 - i want to ask about checkbox/uncheckbox all 我想问一下下面代码的含义 - I want to ask the meaning of the following code 我想问一下行的总和 - I want ask about sum of rows 我在材质 UI 选项卡中有错误为“道具类型失败:不支持道具`children`。 请删除” - I have error in material UI tabs as “Failed prop type: The prop `children` is not supported. Please remove it” 在 nextjs 中导入 Image 组件时,如何删除警告“Warning: Prop `style` did not match”? - How do I remove warning "Warning: Prop `style` did not match" when I import Image component in nextjs? 为什么我得到一个数组,其名称是我在索引 0 处分配给道具的名称,而我想在索引 1 处传递的实际道具? - Why am I getting an array with the name I assigned to a prop at index 0, and the actual prop I want to pass at index 1? 使用 GatsbyImage - 我不断收到错误道具类型失败:道具“图像”在“GatsbyImage”中被标记为必需,但其值为“未定义” - Using GatsbyImage - I keep getting an error Failed prop type: The prop `image` is marked as required in `GatsbyImage`, but its value is `undefined` 我想要网站访问者升级他们的浏览器,而不是使用前缀 - Instead of using prefixes I want to ask site visitors to upgrade their browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM