在我用React JSX制作的游戏wiki中,有一个错误:
SyntaxError: The requested module '/src/components/Menu.jsx?t=1724725277296' does not provide an export named 'Menu'
但是,路径是正确的(在 vscode 上使用
CTRL-CLICK
有很大帮助)baseURL
正确导出它。
我尝试在菜单组件中使用括号和方括号,但没有成功。
import React from 'react'
import logo from '../assets/logo.png'
const baseURL = 'http://localhost:5173';
const Menu = () => {
return (
<nav className="navbar navbar-expand-lg bg-dark">
<div className="container-fluid">
<a className="navbar-brand" href="#"><img src={logo} alt="Moncria" height="192" /></a>
<button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNav">
<ul className="navbar-nav">
<li className="nav-item">
<a className="nav-link active text-success" href={baseURL}>Home</a>
</li>
<li className="nav-item">
<a className="nav-link active text-danger" href={`${baseURL}/wiki`}>Wiki</a>
</li>
<li className="nav-item">
<a className="nav-link active text-warning" href={`${baseURL}/users`}>Users</a>
</li>
<li className="nav-item">
<a className="nav-link active" style={{color: '#fc0fc0'}} href={`${baseURL}/register`}>Register</a>
</li>
<li className="nav-item">
<a className="nav-link active text-primary" href={`${baseURL}/register`}>Login</a>
</li>
</ul>
</div>
</div>
</nav>
)
}
export default [ Menu, baseURL ]
你是这样导入的吗?
import { Menu } from '/src/...';
也许可以尝试一下
import MenuConfig from '/src/...';
const [Menu, baseURL] = MenuConfig;