Can't resolve './build/Release/scrypt': Error using GSN v2.0.3


We’ve made great progress implementing GSN on our application since our previous issues (1: RDC Script for Relay, 2: Issue getting valid relay provider).

Here is our current build: We are running into an issue we have been unable to solve after a good deal of effort. If it is of any consequence to our current issue, before reaching the hard block, when we run npm i, we get the following snippet in our terminal output:

> @opengsn/gsn@2.1.0 postinstall /home/****/gatsby-torus-direct-v3/node_modules/@opengsn/gsn
> patch-package

patch-package 6.2.2
Applying patches...
No patch files found

Our main issue is when running npx gatsby build (same as npx run build in create-react-app). The following snippet begins with the last normal line of build output and then our error:

success Building production JavaScript and CSS bundles - 147.959s
success Rewriting compilation hashes - 0.004s
error undefined failed

Can't resolve './build/Release/scrypt' in '/home/****/gatsby-torus-direct-v3/node_modules/scrypt'

If you're trying to use a package make sure that './build/Release/scrypt' is installed. If you're trying to use a local file make sure that the path is correct.
not finished Building static HTML for pages - 15.785s

Here is a list of relevant threads we have crawled for solutions with no luck- most of the more recent posts have no responses:

scrypt is an optional dependency.
try to yarn install --ignore-optional
I did try to checkout and do “gatsby build”, but it fails on other errors…

Hi Dror,

We have reset the directory, including the removal of package-lock.json, then ran yarn install --ignore-optional to no new effect- the output is the same as yarn install or npm i --no-optional. Using this we tried configuring scrypt as an optional dependency in package.json by removing it from dependencies and adding it to optionalDependencies as well.

Please advise if there is another way (not this way: to specify optional dependencies, or another potential solution!

I found a workaround for the scrypt issue.

Somehow, gatsby manages to force all require commands to execute, even if they are wrapped and exception-catched.
(probably its not gatsby itself, but webpack or something, but its strange that it works OK for other frameworks like React)

I added a patch file like so:

 $ cat patches/scrypt.js+0.3.0.patch
diff --git a/node_modules/scrypt.js/index.js b/node_modules/scrypt.js/index.js
index 363eb3a..d4e79ac 100644
--- a/node_modules/scrypt.js/index.js
+++ b/node_modules/scrypt.js/index.js
@@ -1,5 +1,5 @@
 try {
-  module.exports = require('./node')
+  module.exports = require('./js')
 } catch (e) {
   module.exports = require('./js')

and you run it with:

$ npx patch-package
patch-package 6.2.2
Applying patches...
scrypt.js@0.3.0 ✔

If it works good for you, then you need to run it after every install, so add to your package.json

 "scripts": {
+  "postinstall": "patch-package"

(see explanation here