Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经为非对称加密安装了 JSEncrypt npm 包。但是当我运行项目时,出现以下错误
服务器错误 ReferenceError: 未定义窗口
我什至尝试在项目中动态加载 JSEncrypt.min.js 文件。
有人可以帮助解决这个问题吗?
那是因为window在服务器端渲染时未定义。 导入组件(包括 JSEncrypt)next/dynamic并将 SSR 设置为 false 应该可以解决问题。 前任。
window
next/dynamic
import dynamic from 'next/dynamic' const ComponentWithJSEncrypt = dynamic( () => import('../components/myComponent'), // path of your component { ssr: false } )