gpt4 book ai didi

node.js - React 无法编译reactLifecyclesCompat 错误

转载 作者:行者123 更新时间:2023-12-03 14:18:07 26 4
gpt4 key购买 nike

我的 react 有问题。它的编译错误显示:

Failed to compile

./node_modules/reactstrap/dist/reactstrap.es.js
Attempted import error: 'react-lifecycles-compat' does not contain a default export (imported as 'reactLifecyclesCompat').

Error screenshot

我有以下依赖项

"dependencies": {
"bootstrap": "^4.1.1",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-lifecycles-compat": "^3.0.4",
"react-scripts": "2.1.2",
"react-transition-group": "^2.5.2",
"reactstrap": "^7.0.0",
"uuid": "^3.3.2"
}

然后我创建了一个 AppNavbar 组件,它只是一个简单的导航栏,位于“src/components/”位置,下面是我的 AppNavbar 组件代码,它导出于文件末尾。

import React, { Component } from 'react';
import {
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
Container
} from 'reactstrap';

class AppNavbar extends Component {
state = {
isOpen: false
}

toggle = () => {
this.setState({
isOpen: !this.state.isOpen
})
}

render() {
return (
<div>
<Navbar color="dark" dark expand="sm" className="mb-5">
<Container>
<NavbarBrand href="/">Shopping List!</NavbarBrand>
<NavbarToggler onClick={this.toggle} />
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink href="https://about.me">About</NavLink>
</NavItem>
</Nav>
</Collapse>
</Container>
</Navbar>
</div>
);
}
}

export default AppNavbar;

然后为了在页面上显示它,我将 AppNavbar 导入到 App.js 中,如下所示:

import React, { Component } from 'react';
import AppNavbar from './components/AppNavbar';

import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';

class App extends Component {
render() {
return (
<div className="App">
<AppNavbar />
</div>
);
}
}

export default App;

最佳答案

不是代码中的错误,而是 reactstrap 导入所需依赖项的方式错误。看看:https://github.com/reactstrap/reactstrap/issues/1343 .

关于node.js - React 无法编译reactLifecyclesCompat 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53980198/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com