【问题标题】:How do I fix deployment error "OSSL_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED is not defined" when using ZEIT Now, Next.js, and Gun.js?使用 ZEIT Now、Next.js 和 Gun.js 时,如何修复部署错误“OSSL_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED 未定义”?
【发布时间】:2019-12-05 16:29:32
【问题描述】:

由于 Gun.js 引用错误 OSSL_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED is not defined,我无法通过 ZEIT Now 部署 Next.js 应用程序。在我的本地机器上以开发模式运行时没有错误。

在部署日志中的错误之前是消息“node-webcrypto-ossl and text-encoding may not be included in default, please add it to your package.json!”这样做并没有解决错误,也没有按照https://github.com/amark/gun#additional-cryptography-libraries 添加@trust/webcrypto(我使用SEA 进行用户身份验证)(编辑:从依赖项中删除了@trust/webcrypto)。

来自 Now 部署日志的堆栈跟踪:

Compiled with warnings.
./node_modules/gun/gun.js
Critical dependency: the request of a dependency is an expression
./node_modules/gun/sea.js
Critical dependency: the request of a dependency is an expression
./node_modules/gun/gun.js
Critical dependency: the request of a dependency is an expression
./node_modules/gun/sea.js
Critical dependency: the request of a dependency is an expression
Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!
node-webcrypto-ossl and text-encoding may not be included by default, please add it to your package.json!
> Build error occurred
ReferenceError: OSSL_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED is not defined
    at /tmp/173ebd33/.next/serverless/pages/index.js:13474:7
    at /tmp/173ebd33/.next/serverless/pages/index.js:13301:7
    at /tmp/173ebd33/.next/serverless/pages/index.js:13478:5
    at Object.<anonymous> (/tmp/173ebd33/.next/serverless/pages/index.js:14596:2)
    at Object.md/m (/tmp/173ebd33/.next/serverless/pages/index.js:14597:30)
    at __webpack_require__ (/tmp/173ebd33/.next/serverless/pages/index.js:23:31)
    at Object.1TCz (/tmp/173ebd33/.next/serverless/pages/index.js:865:11)
    at __webpack_require__ (/tmp/173ebd33/.next/serverless/pages/index.js:23:31)
    at Module.VVmT (/tmp/173ebd33/.next/serverless/pages/index.js:11281:12)
    at __webpack_require__ (/tmp/173ebd33/.next/serverless/pages/index.js:23:31)
    at /tmp/173ebd33/.next/serverless/pages/index.js:91:18
    at Object.<anonymous> (/tmp/173ebd33/.next/serverless/pages/index.js:94:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
npm
 ERR! code ELIFECYCLE
npm
 ERR! errno 1
npm
 ERR! maptivist@1.0.0 now-build: `next build`
npm ERR!
 Exit status 1
npm ERR!

npm ERR! Failed at the maptivist@1.0.0 now-build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

package.json 依赖:

{
  "dependencies": {
    "directory-named-webpack-plugin": "^4.0.1",
    "gun": "^0.2019.726",
    "mapbox-gl": "^1.2.1",
    "next": "^9.0.3",
    "next-offline": "^4.0.3",
    "node-webcrypto-ossl": "^1.0.48",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "styled-components": "^4.3.2",
    "text-encoding": "^0.7.0"
  }
}

node-webcrypto-osslpackage-lock.json 中的相关内容:

...
"gun": {
  "version": "0.2019.726",
  "resolved": "https://registry.npmjs.org/gun/-/gun-0.2019.726.tgz",
  "integrity": "sha512-LVSxhGwaemZbrirSk6fp2KXORLUyjs6bnssjSjl/OhwbfLv7fvMhNfaOZuorzYsehxqMKJvxyNdFq/mZNXpjHQ==",
  "requires": {
    "emailjs": "^2.2.0",
    "node-webcrypto-ossl": "^1.0.47",
    "text-encoding": "^0.7.0",  
    "ws": "~>7.1.0"
  }
},
...
"node-webcrypto-ossl": {
  "version": "1.0.48",
  "resolved": "https://registry.npmjs.org/node-webcrypto-ossl/-/node-webcrypto-ossl-1.0.48.tgz",
  "integrity": "sha512-MWUkQ/5wrs7lpAr+fhsLMfjdxKGd3dQFVqWbNMkyYyCMRW8E7ScailqtCZYDLTnJtU6B+91rXxCJNyZvbYaSOg==",
  "requires": {
    "mkdirp": "^0.5.1",
    "nan": "^2.13.2",
    "tslib": "^1.9.3",
    "webcrypto-core": "^0.1.26"
  }
},
...

node-webcrypto-osslnode_modules 中可见。

请帮忙! :-)

【问题讨论】:

    标签: next.js gun vercel


    【解决方案1】:

    @randy-morantes 你的package.json 看起来是正确的。

    你能分享一下吗:

    • 错误的堆栈跟踪。
    • 您调用 gun 的服务器代码会导致此问题。

    【讨论】:

    • 已编辑以包含堆栈跟踪。关于您的第二个请求,我没有编写任何服务器代码,因为我试图让事情尽可能“无服务器”。如果有帮助,可以在 github.com/rmorantes/maptivist 找到应用程序存储库。对于耽搁的时间,我深表歉意!
    【解决方案2】:

    我是奇怪的\webcrypto 和 node-webcrypto-ossl 包的作者。根据枪的来源:

    https://github.com/amark/gun/blob/e0d85f02b567a43d39cda0fe71522b84ff52a08b/sea/shim.js#L25

    看起来他们还没有切换到奇怪的\webcrypto。尝试将 node-webcrypto-ossl 添加到您的 package.json。

    【讨论】:

    • 我不太明白,node-webcrypto-ossl 已经在我的package.json 中(参见 OP 中的第一个代码块)。
    • 对不起,我看到了@trust/webcrypto 包,没有再看;我很惊讶两人都在里面。它们在理论上会相互冲突。节点。你在包目录中看到 node-webcrypto-ossl 了吗?
    • 别担心!文档中对@trust/webcrypto 的引用现在已经消失了,所以我猜他们只是还没有更新。我已经卸载了@trust/webcrypto,但仍然遇到同样的部署错误。我在package-lock.json(向OP 中添加了代码块)和node_modules 中看到了node-webcrypto-ossl
    • 我们现在只使用@rmhrisk 的代码,太棒了! @trust/webcrypto 不需要。也许 zeit 无法使用 node-gyp 构建?
    【解决方案3】:

    最新版本的 Next.js("next": "9.0.4""next-offline": "4.0.5")修复了这个问题!

    【讨论】:

      【解决方案4】:

      我昨晚遇到了这个问题,最后使用猴子补丁和破解成功解决了这个问题。诀窍是将 gunsea 从 webpack 和 react 环境中取出,然后使用 window.gun 访问它。此外,gun 不在 webpack 中时似乎运行得更快。

      这就是我在 Gatsbyjs 项目中的做法:

      阅读此文档:https://www.gatsbyjs.org/docs/custom-html/

      1. 将 ./cache/default-html.js 复制到 ./src/html.js
      2. 现在在 html.js 中启动 gun and sea。您可以在此处从 github 或 jsdelivr 加载外部 js 文件。
      3. 然后在你的 gatsby react 组件中,只需调用 window.gun 和 window.user 即可享受黑客攻击:

        如果(窗口)枪...

      4. 现在运行gatsby build,你可以看到它已经正确构建了。

      【讨论】:

        猜你喜欢
        • 2019-05-12
        • 2019-10-11
        • 2020-01-15
        • 2019-12-05
        • 2020-10-04
        • 2019-06-23
        • 2018-12-16
        • 1970-01-01
        • 2019-08-09
        相关资源
        最近更新 更多