Fix problem with bcrypt library linkage breaking in dev
metasoarous opened this issue · 6 comments
Had trouble getting the system started with docker-compose with the dev overlay because I kept getting an error like Error: Cannot find module .... bcrypt
.
This seemed to have been caused by some build directory corruption, and was fixed by the suggestion here of running npm rebuild
. Of course, this had to be done from within the polis-server
container, so the trick is to get the system running, then run docker ps
to find the process id, then use that in the command docker exec -it xxxxxxxx /bin/sh
to get a shell, from which npm rebuild
can be executed.
Any additional context which might be relevant?
I've had similar problems with primordials
in the past which might have been fixed by doing this.
I wish there was a way to get fresh builds every time (for sure), but this might have to do with the image mapping (as a dev convenience), combined with some failure of npm to do the right thing.
Now seeing this manifest in a slightly different manner with Error: Error loading shared library /app/node_modules/bcrypt/lib/binding/napi-v3/brcypt-lib.node: Exec format error
This time, the npm rebuild
trick did not work for the user. After a little research, it seemed like adding node_modules
to the server/.dockerignore
might fix things, but as it turns out, this is already in our dockerignore 🤔
Very unclear why this issue is manifesting this way, but it only seems to occur when trying to run in development mode, so maybe this has to do with the typescript watch somehow.
In any case, clear now that this is an actual bug (if intermittent) that needs to be solved, not just a transient issue due to old build state on my machine (this new error was reported by a new developer just firing up the project).
This message might be relevant (from the npm build log):
Pre-built binaries not installable for bcrypt@5.0.1 and node@14.14.0 (node-v83 ABI, musl) (falling back to source compile with node-gyp)
@sirodoht Thanks again for helping debug this! I'm sorry we weren't able to get it resolved sooner while the hack night was still ongoing, but I think I figured out why switching to bcryptjs didn't work. There was an additional server file that we needed to update to refer to bcryptjs (also, it took a couple of starts for the change to get picked up). Anyway, this should be resolved now, and I'd greatly appreciate it if you'd give it another whirl when you have time.
Thanks again!
Just tried and it works now! I think the problem wasn't the second file after all, but the fact that I didn't rm -rf node_modules
. Anyhoo, all good now 👌
Excellent! Glad to hear it.
And yes, not cleaning out the node_modules
may have been what led me to have to rerun a couple times to get it working.
Nevertheless, on my first pass through it didn't work, and I very nearly missed that the error the second time around was coming not from server.ts
, but from auth/password.ts
(easy to miss in part because server.ts
was still showing up in the trace, since it's what requires `passwords.ts).
Anyway; Glad to have this resolved, whatever the original issue actually was. Thanks again for persisting on this with me!
using bcryptjs instead of bcrypt solved my issue
Now seeing this manifest in a slightly different manner with
Error: Error loading shared library /app/node_modules/bcrypt/lib/binding/napi-v3/brcypt-lib.node: Exec format error
This time, the
npm rebuild
trick did not work for the user. After a little research, it seemed like addingnode_modules
to theserver/.dockerignore
might fix things, but as it turns out, this is already in our dockerignore 🤔Very unclear why this issue is manifesting this way, but it only seems to occur when trying to run in development mode, so maybe this has to do with the typescript watch somehow.
In any case, clear now that this is an actual bug (if intermittent) that needs to be solved, not just a transient issue due to old build state on my machine (this new error was reported by a new developer just firing up the project).
using bcryptjs instead of bcrypt solved my issue