在 next js 13 中使用新的“app 目录”导入 bootstrap js 文件的位置

Bha*_*rma 6 next.js bootstrap-5 next.js13

我在下一个 js 13 中使用新的应用程序目录,当使用 bootstrap 下拉菜单时,只有 UI 可以工作,bootstrap 的 js 功能在其中不起作用。我尝试在layout.tsx中导入js文件,但它抛出了这个错误=>

文档未定义

在此输入图像描述

布局.tsx

import 'bootstrap/dist/js/bootstrap.min.js';
import './globals.css';
import './styles/index.scss';

export const metadata = {
    title: 'Create Next App',
    description: 'Generated by create next app',
};

export default function RootLayout({
    children,
}: {
    children: React.ReactNode;
}) {
    return (
        <html lang='en'>
            <body>{children}</body>
        </html>
    );
}
Run Code Online (Sandbox Code Playgroud)

小智 0

在您的孩子中,您使用了文档对象,并且发生了此错误,因为页面在您进入浏览器之前已渲染,因此文档未定义以修复此用途typeof document !== "undefind" && "do something"