Replit环境下Node+Prisma ORM执行数据库填充时遇OpenSSL错误
Replit中Prisma Seed失败:找不到libssl.so.1.1的解决方法
问题详情
运行npm run seed执行数据库填充时触发以下错误:
Prisma cannot find the required libssl system library in your system. Please install openssl-1.1.x and try again.
完整错误栈:
runner@e4d694f9ada7:~/node-prisma-repl-hello-world$ npm run seed > nodejs@1.0.0 seed > tsx prisma/seed.ts PrismaClientInitializationError: Invalid `prisma.user.create()` invocation in /home/runner/node-prisma-repl-hello-world/prisma/seed.ts:13:17 10 async function main() { 11 // Create sample users 12 const users = await Promise.all([ → 13 prisma.user.create( Unable to require(`/home/runner/node-prisma-repl-hello-world/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node`). Prisma cannot find the required `libssl` system library in your system. Please install openssl-1.1.x and try again. Details: libssl.so.1.1: cannot open shared object file: No such file or directory at Mn.handleRequestError (/home/runner/node-prisma-repl-hello-world/node_modules/@prisma/client/runtime/library.js:121:7638) at Mn.handleAndLogRequestError (/home/runner/node-prisma-repl-hello-world/node_modules/@prisma/client/runtime/library.js:121:6663) at Mn.request (/home/runner/node-prisma-repl-hello-world/node_modules/@prisma/client/runtime/library.js:121:6370) at async l (/home/runner/node-prisma-repl-hello-world/node_modules/@prisma/client/runtime/library.js:130:9633) at async Promise.all (index 0) at main (/home/runner/node-prisma-repl-hello-world/prisma/seed.ts:12:17) { clientVersion: '6.0.1', errorCode: undefined }
项目package.json配置:
{ "name": "nodejs", "version": "1.0.0", "type": "module", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "tsx src/index.ts", "seed": "tsx prisma/seed.ts" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@prisma/client": "^6.0.1", "prisma": "^6.0.1", "tsx": "^4.7.0" }, "devDependencies": { "@types/node": "^22.10.1", "typescript": "^5.7.2" } }
复现步骤:
- 执行
npm install - 执行
npx prisma migrate deploy - 执行
npm run seed
已尝试的无效操作:
- 通过config.nix和依赖面板安装openssl
- 切换AWS/Supabase远程数据库
- 升级Prisma至6.1.0 LTS版本
解决方案
方案1:使用Prisma Wasm引擎(推荐)
Wasm引擎不依赖系统级libssl库,直接通过环境变量切换:
- 在项目根目录的
.env文件中添加:PRISMA_CLIENT_ENGINE_TYPE=wasm - 重新生成Prisma客户端:
npx prisma generate - 再次执行seed命令:
npm run seed
方案2:配置Nix环境加载openssl-1.1
Replit基于NixOS,需通过config.nix明确指定openssl-1.1并设置库路径:
- 创建或修改项目根目录的
config.nix文件:{ pkgs }: { deps = [ pkgs.openssl_1_1 pkgs.nodejs ]; env = { LD_LIBRARY_PATH = "${pkgs.openssl_1_1.lib}/lib:$LD_LIBRARY_PATH"; }; } - 重启Repl使配置生效
- 重新执行
npm run seed
方案3:强制指定查询引擎版本
若上述方案无效,可手动指定兼容Replit环境的查询引擎:
- 在
.env中添加:PRISMA_QUERY_ENGINE_LIBRARY=node_modules/.prisma/client/libquery_engine-debian-openssl-3.x.so.node - 重新生成客户端并执行seed:
npx prisma generate && npm run seed
内容的提问来源于stack exchange,提问作者Parth Ahuja
相关产品推荐
相关产品推荐

