prisma: Cannot access engine inside vercel/pkg

Dear community,

I’m having a problem to use prisma inside a vercel/pkg in which i’m getting an ENOENT error like:

spawn /snapshot/enoent-problem/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x ENOENT 

To narrow down the issue i’ve created a sample application here

To reproduce the issue:

I’m running the packaged app as :

npm i
npx prisma generate
npx pkg package.json --debug --output bin/exe > log-pkg.log
env -i DEBUG_PKG=1 bin/exe

and getting the following error

spawn called cwd: <exec_path>/enoent-problem and dirname: /snapshot/enoent-problem
[Arguments] {
  '0': '/snapshot/enoent-problem/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x',
  '1': [ 'cli', 'get-config' ],
  '2': {
    maxBuffer: 100000000,
    buffer: true,
    stripFinalNewline: true,
    extendEnv: true,
    preferLocal: false,
    localDir: '/snapshot/enoent-problem/node_modules/.prisma/client',
    execPath: '<exec_path>/enoent-problem/bin/exe-node16-linuxstatic',
    encoding: 'utf8',
    reject: true,
    cleanup: true,
    all: false,
    windowsHide: true,
    env: {
      DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/<table_name>?schema=public',
      PRISMA_DML_PATH: '/snapshot/enoent-problem/node_modules/.prisma/client/schema.prisma',
      RUST_BACKTRACE: '1',
      RUST_LOG: 'info',
      LOG_QUERIES: 'true',
      OVERWRITE_DATASOURCES: '[]'
    },
    cwd: '/snapshot/enoent-problem/node_modules/.prisma/client',
    stdio: [ undefined, undefined, undefined ]
  }
}
spawn called cwd: <exec_path>/enoent-problem and dirname: /snapshot/enoent-problem
[Arguments] {
  '0': '/snapshot/enoent-problem/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x',
  '1': [ '--enable-raw-queries', '--port', '33491' ],
  '2': {
    env: {
      DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/<table_name>?schema=public',
      PRISMA_DML_PATH: '/snapshot/enoent-problem/node_modules/.prisma/client/schema.prisma',
      RUST_BACKTRACE: '1',
      RUST_LOG: 'info',
      LOG_QUERIES: 'true',
      OVERWRITE_DATASOURCES: '[]'
    },
    cwd: '/snapshot/enoent-problem/node_modules/.prisma/client',
    windowsHide: true,
    stdio: [ 'ignore', 'pipe', 'pipe' ]
  }
}
prisma:error  in Could not start query engine
spawn /snapshot/enoent-problem/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x ENOENT
Error:  PrismaClientKnownRequestError2 [PrismaClientKnownRequestError]: 
Invalid `prisma.challenge.findMany()` invocation:


  spawn /snapshot/enoent-problem/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x ENOENT
    at cb (/snapshot/enoent-problem/node_modules/@prisma/client/runtime/index.js:34800:17)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ENOENT',
  clientVersion: '2.27.0',
  meta: undefined
}

I’ve confirmed that binary has been copied inside the pkg (with pkg --debug) and make sure it’s there in virtual fs (with DEBUG_PKG=1 env) but still couldn’t figure out the cause of the error. And I can execute the same app without and problem outside pkg with npm start or spawn other binaries inside pkg. I tried so far:

  • To specify PRISMA_QUERY_ENGINE_BINARY outside pkg
  • Different engines and different pkg targets but no dice.

So I’d appreciate if you can help me to figure out what the binary compatibility problem in pkg environment is. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (9 by maintainers)

Most upvoted comments

I had the same problem and solved it by just including the prisma query engine binary path in pkg assets:

package.json

{
    "pkg": {
        "assets": [
            "node_modules/.prisma/client/*.node"
        ]
    }
}

I think your getPrismaPath method returns an absolute path, certainly if it’s set by an envvar, so I think if you remove the cwd flag from the spawn call (linked above) it should unbreak pkg without breaking any existing integration.

But still getting the ENOENT exception. So I’m suspecting something in engine binary blocking the call.

Our Engines don’t do anything like that, it is more probably that something inside pkg does not know how to handle how to call a binary or resolve that path.

The Go Client, which uses pkg to package the CLI, downloads all Engines manually and sets the environment variables (https://www.prisma.io/docs/reference/api-reference/environment-variables-reference#binary-environment-variables) to known paths outside of the package CLI - that seems to work.

(We currently suspect that our e2e tests for pkg only work, as the temporary location where pkg parks the files when creating the package, is still present when we execute the test: https://github.com/prisma/e2e-tests/tree/dev/binaries/pkg)

Open a new discussion please @ParseDark where you describe your problem.↳

Got it. Will create a simple project for reproduce this issue. Thanks.