next.js - window is not defind 解决方法

使用next.js在引入其他组件或者模块可能会出现报错

ReferenceError: window is not defined
...

解决方法

使用next动态引入模块或组件

import <模块名> from 'next/dynamic';
const Module = dynamic(
    import('<模块名>'),
    { ssr: false }
);

使用模块或组件


or

Module()

你可能感兴趣的:(next.js - window is not defind 解决方法)