这个弹窗是 macOS 的 Gatekeeper 安全机制 阻止你加载 bcrypt_lib.node
文件,因为它不是 Apple 签名的文件。
你想 "忽视" 它,其实是让系统允许这个 .node
原生模块运行,解决方式如下:
sudo xattr -d com.apple.quarantine node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node
✅ 最直接有效的解决办法(终端允许这个库)
1. 找到你项目中出错的 bcrypt_lib.node
文件路径(例如):
bash
node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node
如果不确定路径,运行项目时报错会提示
bcrypt_lib.node
的全路径。
2. 用 终端命令解锁并允许其运行
bash
sudo xattr -d com.apple.quarantine node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node
⛳️ 如果你的文件在
napi-v6
、napi-v1
等路径下,请根据你项目中提示的路径替换。
📌 这个命令的作用:
xattr
:修改文件的扩展属性-d com.apple.quarantine
:删除"隔离标签",告诉系统这不是恶意软件- 用
sudo
是因为这个文件夹在node_modules
下,需要管理员权限
🧩 如果你使用的是 yarn
或 pnpm
安装的 bcrypt:
不同包管理器路径略有不同,也可能是:
bash
node_modules/@node-rs/bcrypt/bcrypt_lib.node
一样使用:
bash
sudo xattr -d com.apple.quarantine 路径/bcrypt_lib.node
✅ 之后运行你的项目就不会报错了
bash
npm run start
# 或
npx expo start
🚫 你不应该"删除"或"忽视"这个库
因为:
bcrypt_lib.node
是bcrypt
库的核心加密原生模块- 忽视/删除它会导致密码无法加密或验证
💡 如果你不想用 bcrypt(可选方案)
你也可以改用纯 JS 实现的 bcryptjs
,它没有 native 模块:
bash
npm uninstall bcrypt
npm install bcryptjs
使用方式类似:
js
const bcrypt = require('bcryptjs');
const hash = await bcrypt.hash(password, 10);
const match = await bcrypt.compare(password, hash);
✅ 总结(推荐你执行的指令):
bash
sudo xattr -d com.apple.quarantine node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node
执行后再次运行项目即可。
如果你需要我根据你的报错路径帮你精确拼出这条命令,也可以贴出报错路径或全路径,我来帮你写。