简体   繁体   English

尝试导入错误:'Jumbotron 未从'react-bootstrap'导出(导入为'Jumbo')

[英]Attempted import error: 'Jumbotron is not exported from 'react-bootstrap' (imported as 'Jumbo')

I'm getting started learning React and trying to create a Jumbotron element from react-bootstrap.我开始学习 React 并尝试从 react-bootstrap 创建一个 Jumbotron 元素。 I'm pretty sure I've installed all the correct modules with npm install react-bootstrap bootstrap , but I'm getting a console error that says "Attempted import error: 'Jumbotron is not exported from 'react-bootstrap' (imported as 'Jumbo')".我很确定我已经安装了所有正确的模块npm install react-bootstrap bootstrap ,但是我收到一个控制台错误,上面写着“尝试导入错误:'Jumbotron 不是从'react-bootstrap'导出的(导入为'巨无霸')”。 My code is as below:我的代码如下:

 import React from 'react'; import { Jumbotron as Jumbo, Container } from 'react-bootstrap'; import styled from 'styled-components'; import boatImage from '../assets/boatImage.jpg'; const Styles = styled.div `.jumbo { background: url(${boatImage}) no-repeat fixed bottom; background-size: cover; color: #efefef; height: 200px; position: relative; z-index: -2; }.overlay { background-color: #000; opacity: 0.6; position: absolute; top: 0; left: 0; bottom: 0; right: 0; z-index: -1; } `; export const Jumbotron = () => ( <Styles> <Jumbo fluid className="jumbo"> <div className="overlay"></div> <Container> <h1>My App</h1> <p>Hello World</p> </Container> </Jumbo> </Styles> )

And here is my package.json:这是我的 package.json:

{
  "name": "landing-page",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "bootstrap": "^5.0.2",
    "husky": "^7.0.1",
    "lint-staged": "^11.1.1",
    "prettier": "^2.3.2",
    "react": "^17.0.2",
    "react-bootstrap": "^2.0.0-beta.4",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "styled-components": "^5.3.0",
    "web-vitals": "^1.1.2"
  },
  "lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
      "prettier --write"
    ]
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "devDependencies": {
    "@babel/core": "^7.14.8"
  }
}

Am I importing it wrong somehow?我以某种方式导入错误吗? Or is there some dependency issue?还是存在一些依赖性问题? Everything else from react-bootstrap appears to be working properly. react-bootstrap 的其他一切似乎都正常工作。 Thanks in advance.提前致谢。

JumboTron doesnt work in bootstrap 5, so if you installed the latest version following the guide on https://react-bootstrap.github.io/ , you have the newer version of react-bootstrap. JumboTron 在 bootstrap 5 中不起作用,因此如果您按照https://react-bootstrap.github.io/上的指南安装了最新版本,您将拥有较新版本的 react-bootstrap。

I saw you followed the tutorial from Brice Ayres he uses bootstrap 4.3.1我看到你遵循了 Brice Ayres 的教程,他使用的是 bootstrap 4.3.1

here's information on what you can do: https://getbootstrap.com/docs/5.0/migration/#jumbotron以下是有关您可以做什么的信息: https : //getbootstrap.com/docs/5.0/migration/#jumbotron

Edit 1: Basically, drop the Jumbotron, make your and own header using react-bootstrap your own css.编辑 1:基本上,放下 Jumbotron,使用 react-bootstrap 制作你自己的标题你自己的 css。 Its very easy它很容易

 U won't be able to use Jumbotron as it is no longer available in the latest Bootstrap 5 import {Jumbotron} from "reactstrap"; in Home.js won't work if u have the latest Bootstrap as it was removed. Add the below CSS in App.css file and insted of using <Jumbotron></Jumbotron> use <div class="jumbotron">

 .container-fluid.jumbotron, .container.jumbotron { border-radius: 6px; padding-left: 15px; padding-right: 15px; } @media screen and (min-width: 768px) {.container-fluid.jumbotron, .container.jumbotron { padding-left: 60px; padding-right: 60px; } } @media screen and (min-width: 768px) {.jumbotron { padding-bottom: 48px; padding-top: 48px; } }.jumbotron { background-color: #eee; padding-left: 60px; padding-right: 60px; margin-bottom: 30px; padding-bottom: 30px; padding-top: 30px; }

 

Kindly uninstall the bootstrap by doing npm uninstall react-bootstrap bootstrap then install it again with the command npm install react-bootstrap bootstrap@4.6.0 Major versions of Bootstrap tend not be be very backwards compatible with each other.请通过执行 npm uninstall react-bootstrap bootstrap 卸载引导程序,然后使用命令 npm install react-bootstrap bootstrap@4.6.0 重新安装引导程序的主要版本往往不会相互向后兼容。 This should work.这应该有效。

Jumbotron is part of react-bootstrap v3.3.x which uses React.Jumbotron是 react-bootstrap v3.3.x 的一部分,它使用 React。

It is not part of react-bootstrap 2.0.0-beta.4 which you are using and which is based on a much older major version of Bootstrap.它不是您正在使用的react-bootstrap 2.0.0-beta.4 的一部分,它基于更旧的 Bootstrap 主要版本。

(Major versions of Bootstrap tend not be be very backwards compatible with each other. (Bootstrap 的主要版本往往不是非常向后兼容。

Jumbotron doesn't work in bootstrap 5. So If you have install latest version of bootstrap, you can either revert back to lower version. Jumbotron 在 bootstrap 5 中不起作用。因此,如果您安装了最新版本的 bootstrap,您可以恢复到较低版本。 However if you wish to continue with this version you can use following code snippet:但是,如果您希望继续使用此版本,可以使用以下代码片段:

<div class="container-fluid bg-light text-dark p-5">
  <div class="container bg-light p-5">
    <h1 class="display-4 fw-bold">Welcome to Admin Dashboard</h1>
    <hr>
      <p>Go to My Website</p>
      <a href="#" class="btn btn-primary">link</a>
  </div>
</div>

Also go to this link and use "inspect element" feature to make modifications in above code snippet as per you need.另请转到此链接并使用“检查元素”功能根据需要对上述代码片段进行修改。 Jumbotron Example超大屏幕示例

我知道我的回复可能对你来说迟了,但它会帮助其他人......你可以在新版本的引导程序中使用它的 className 而不是它的组件

<div className="jumbotron">.....</div>

暂无
暂无

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

相关问题 尝试导入错误:“Toast”未从“react-bootstrap”导出 - Attempted import error: 'Toast' is not exported from 'react-bootstrap' 尝试导入错误:“BrowseRouter”未从“react-router-dom”导出(导入为“Router”) - Attempted import error: 'BrowseRouter' is not exported from 'react-router-dom' (imported as 'Router') 尝试导入错误:“app”未从“firebase/app”导出(导入为“firebase”) - Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase') 尝试导入错误:“create”未从“fontkit”导出(导入为“fontkit”) - Attempted import error: 'create' is not exported from 'fontkit' (imported as 'fontkit') 无法在React.js中导入d3队列? 尝试导入错误:“队列”未从“d3”导出(导入为“d3”) - Can't import d3-queue in React.js? Attempted import error: 'queue' is not exported from 'd3' (imported as 'd3') 尝试导入错误:'未从 - Attempted import error:' is not exported from 反应错误“尝试导入错误:'TodoItem'未从'./Todoitem'导出。” - error in react " Attempted import error: 'TodoItem' is not exported from './Todoitem'. " 尝试导入错误:“getMoviesList”未从“./actions”导出; 反应错误 redux - Attempted import error: 'getMoviesList' is not exported from './actions'; error in react redux 尝试导入错误:“useDispatch”未从“react-redux”导出 - Attempted import error: 'useDispatch' is not exported from 'react-redux' 尝试导入错误:“withRouter”未从“react-router”导出 - Attempted import error: 'withRouter' is not exported from 'react-router'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM