Search code examples
next.jsgunvercel

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?


I've been unable to deploy a Next.js app via ZEIT Now due to a Gun.js reference error, OSSL_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED is not defined. There are no errors when running in development mode on my local machine.

Just prior to the error in the deployment logs is the message "node-webcrypto-ossl and text-encoding may not be included by default, please add it to your package.json!" Doing so did not fix the error, nor did adding @trust/webcrypto as per https://github.com/amark/gun#additional-cryptography-libraries (I'm using SEA for user authentication) (EDIT: removed @trust/webcrypto from dependencies).

Stack trace from Now deployment logs:

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! [email protected] now-build: `next build`
npm ERR!
 Exit status 1
npm ERR!

npm ERR! Failed at the [email protected] now-build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

package.json dependencies:

{
  "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-ossl-related stuff in package-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-ossl is visible in node_modules.

Please help! :-)


Solution

  • The latest version of Next.js ("next": "9.0.4", "next-offline": "4.0.5") fixed the issue!