question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get `Unable to load Node-API Library` when using prisma in docker container from gcr.io/distroless/nodejs18-debian11

See original GitHub issue

Bug description

When using prisma in gcr.io/distroless/nodejs18-debian11. I got this error

/app/node_modules/@prisma/client/runtime/index.js:34316
      throw new PrismaClientInitializationError(message, this.client._clientVersion);
            ^

PrismaClientInitializationError:
Invalid `prisma.user.count()` invocation in
/app/index.js:5:13

  2
  3 const prisma = new PrismaClient();
  4
→ 5 prisma.user.count(
Unable to load Node-API Library from /app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node, Library may be corrupt
    at RequestHandler.handleRequestError (/app/node_modules/@prisma/client/runtime/index.js:34316:13)  
    at /app/node_modules/@prisma/client/runtime/index.js:34737:25
    at async PrismaClient._executeRequest (/app/node_modules/@prisma/client/runtime/index.js:35301:22) 
    at async PrismaClient._request (/app/node_modules/@prisma/client/runtime/index.js:35273:16) {      
  clientVersion: '4.6.0',
  errorCode: undefined
}

How to reproduce

  1. Clone https://github.com/vimutti77/prisma-napi-distroless-bug
  2. Run npm run build
  3. Run npm run start
  4. See error

Expected behavior

It should no error and log count: 0

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}
const { PrismaClient } = require("@prisma/client");

const prisma = new PrismaClient();

prisma.user.count().then((count) => {
  console.log(`count: ${count}`);
});

Environment & setup

  • OS: gcr.io/distroless/nodejs18-debian11
  • Database: SQL Server
  • Node.js version: 18

Prisma Version

I got this error when I try to check the prisma version inside the docker container

Error: Unable to require(`/app/node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node`)
 libz.so.1: cannot open shared object file: No such file or directory
    at load (/app/node_modules/prisma/build/index.js:89146:11)
    at getEngineVersion (/app/node_modules/prisma/build/index.js:89944:16)
Error: Command failed with exit code 127: /app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x --version
/app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
    at makeError (/app/node_modules/prisma/build/index.js:3641:18)
    at handlePromise (/app/node_modules/prisma/build/index.js:4409:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)     
    at async getEngineVersion (/app/node_modules/prisma/build/index.js:89947:20) {    
  shortMessage: 'Command failed with exit code 127: /app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x --version',
  command: '/app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x --version',
  escapedCommand: '"/app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x" --version',
  exitCode: 127,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: '/app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
Error: Command failed with exit code 127: /app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x --version
/app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
    at makeError (/app/node_modules/prisma/build/index.js:3641:18)
    at handlePromise (/app/node_modules/prisma/build/index.js:4409:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)     
    at async getEngineVersion (/app/node_modules/prisma/build/index.js:89947:20) {    
  shortMessage: 'Command failed with exit code 127: /app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x --version',
  command: '/app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x --version',
  escapedCommand: '"/app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x" --version',
  exitCode: 127,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: '/app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
prisma                  : 4.6.0
@prisma/client          : 4.6.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : E_CANNOT_RESOLVE_VERSION (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : E_CANNOT_RESOLVE_VERSION (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : E_CANNOT_RESOLVE_VERSION (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 2e719efb80b56a3f32d18a62489de95bb9c130e3 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.6.0-53.2e719efb80b56a3f32d18a62489de95bb9c130e3
Default Engines Hash    : 2e719efb80b56a3f32d18a62489de95bb9c130e3
Studio                  : 0.476.0

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
iamchaniicommented, Dec 14, 2022

I faced same issue. this is my workaround: set up image tag explicitly to use alpine 3.16.

-FROM node:16-alpine
+FROM node:16-alpine3.16
WORKDIR /app
COPY --from=prod-build /app/prod_node_modules ./node_modules
COPY --from=build /app/dist              ./dist
COPY --from=build /app/prisma            ./prisma
COPY --from=build /app/package.json ./package.json
1reaction
josethz00commented, Dec 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix "Unable to load Node-API Library" with Cypress on ...
Here's how to fix the "Unable to Load Node-API Library" error that can come up when trying to use Prisma in Cypress tasks...
Read more >
Why does Prisma run in a Docker container instead of being a ...
I come from a Java ORM background where the ORM tools are all libraries in the form of JARs, like Hibernate. It seems...
Read more >
Introduction to Prisma with Docker - Section.io
In this article we will introduce Primsa. We will learn what Prisma is, how to work with it, and deploy it on a...
Read more >
Prisma won't connect to MySQL Docker Container
When I start the MySQL container solo and run the Prisma migrate command, it works and I can use the backend service like...
Read more >
How To Build a GraphQL API with Node.js, Prisma, Docker ...
Whereas REST is an architectural style, GraphQL is data query and manipulation language for APIs, and a runtime for fulfilling queries with ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found