kelektiv / node.bcrypt.js

bcrypt for NodeJs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use bcrypt v5.1.0 on darwin arm64 architecture (apple m1) with node v18.14.2

Atrus619 opened this issue · comments

I recently updated my node version to 18.14.2 and I can no longer install the bcrypt library on my m1 mac (darwin arm64 architecture).

I've tried installing the library normally, e.g. yarn add bcrypt as well as installing the package directly from the asset, e.g. by adding an entry into my package.json file like "bcrypt": "https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.1.0/bcrypt_lib-v5.1.0-napi-v3-darwin-arm64-unknown.tar.gz"

I had no issues using this library on node 15, but after upgrading I cannot get this to work.
When I try to install the library normally, I get a local certificate error.

When I try to install the library from the tarball, the package installs fine, but when I go to run the code, node complains that the module cannot be found.

Is there an obvious step I am missing in getting this to work?

Thanks!

Same here, on running the code or running tests:

Error: dlopen(/Users/my_user/tfs/my-service/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node, 0x0001): tried: '/Users/my_user/tfs/my-service/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/my_user/tfs/my-service/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (no such file), '/Users/my_user/tfs/my-service/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

@Atrus619 @recrsn any ideas, followups, had any breakthrough ?

commented

Apparently, bcrypt package deletes itself after the installation is complete, if it does not recognise the installed NodeJS version. A strange behaviour, but the solution is simple.

Switch NodeJS version of your project to version 18.13.0 This can be done as follows
npm install node@18.13.0 --save-exact

Delete node_modules and reinstall using correct nodejs version. Looks like your npm is running under Rosetta

Use npm bcrypt direct in terminal!
most people use npm bcrypt@...version (this will cause issue in your terminal )!

I am having a similar issue on Alpine using Node 18.16.1 with node:18-alpine.

Error: Error loading shared library /workdir/apps/admin-panel/.next/standalone/apps/admin-panel/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: Exec format error
[DATA] admin            |     at Module._extensions..node (node:internal/modules/cjs/loader:1340:18)
[DATA]
[DATA] admin            |     at Module.load (node:internal/modules/cjs/loader:1119:32)
[DATA] admin            |     at Module._load (node:internal/modules/cjs/loader:960:12)
[DATA]
[DATA] admin            |     at Module.require (node:internal/modules/cjs/loader:1143:19)
[DATA] admin            |     at require (node:internal/modules/cjs/helpers:110:18)
[DATA] admin            |     at Object.<anonymous> (/workdir/apps/admin-panel/.next/standalone/apps/admin-panel/node_modules/bcrypt/bcrypt.js:6:16)
[DATA] admin            |     at Module._compile (node:internal/modules/cjs/loader:1256:14)
[DATA] admin            |     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
[DATA] admin            |     at Module.load (node:internal/modules/cjs/loader:1119:32)
[DATA] admin            |     at Module._load (node:internal/modules/cjs/loader:960:12) {
[DATA] admin            |   code: 'ERR_DLOPEN_FAILED'

Although this doesn't really make sense for a Next.js standalone build, I've rerun the npm i, tried reinstalling bcrypt and just can't come up with a solution.

@timheerwagen Check whether the architecture of NodeJs and the arch of bcrypt are same

I was having the same issue as @timheerwagen, and taking what @recrsn said into account I realized that my Dockerfile was copying the node_modules folder from my Mac into the Alpine container. To solve that, I just created the .dockerignore file and added node_modules there.

Error: dlopen(/Users/guotie/guotie/product/0xfollow/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node, 0x0001): tried: '/Users/guotie/guotie/product/0xfollow/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (code signature invalid in <3D272F18-EDBA-3354-87A4-4287566BE808> '/Users/guotie/guotie/product/0xfollow/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (errno=85) sliceOffset=0x00000000, codeBlobOffset=0x000195B0, codeBlobSize=0x000003BC), '/System/Volumes/Preboot/Cryptexes/OS/Users/guotie/guotie/product/0xfollow/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (no such file), '/Users/guotie/guotie/product/0xfollow/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (code signature invalid in <3D272F18-EDBA-3354-87A4-4287566BE808> '/Users/guotie/guotie/product/0xfollow/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' (errno=85) sliceOffset=0x00000000, codeBlobOffset=0x000195B0, codeBlobSize=0x000003BC)
 ❯ Object.<anonymous> ../../node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js:6:16

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_DLOPEN_FAILED' }