【问题标题】:NextJS project compilation fails with JSEncryptNextJS 项目编译因 JSEncrypt 失败
【发布时间】:2021-10-07 15:40:44
【问题描述】:

我已经为非对称加密安装了 JSEncrypt npm 包。 但是当我运行项目时,出现以下错误

服务器错误 ReferenceError: 未定义窗口

我什至尝试在项目中动态加载 JSEncrypt.min.js 文件。

有人可以帮忙解决这个问题吗?

【问题讨论】:

标签: next.js encryption-asymmetric jsencrypt


【解决方案1】:

那是因为window 在服务器端渲染时没有定义。
导入 next/dynamic 并将 SSR 设置为 false 的组件(其中包括 JSEncrypt)应该可以解决问题。
例如。

import dynamic from 'next/dynamic'
const ComponentWithJSEncrypt = dynamic(
  () => import('../components/myComponent'), // path of your component
  { ssr: false }
)

【讨论】:

  • 我试过了。没用
猜你喜欢
  • 1970-01-01
  • 2019-08-02
  • 2017-07-29
  • 2017-07-25
  • 1970-01-01
  • 2019-02-12
  • 1970-01-01
  • 2020-08-21
  • 2020-10-21
相关资源
最近更新 更多