help node sea app with prisma

I created an API using Fastify and bundled it into an executable using Node.js SEA. It works fine on my machine, but when I send it to someone else, it throws an error saying it can't find the query_engine.dll.node file. I’ve figured out that the issue is due to the location of this DLL. Currently, I have to manually recreate the same folder structure (e.g., src/util/prisma/client) next to the executable and place the DLL there for it to work. However, instead of relying on this specific folder structure, I want the executable to load the query_engine.dll.node directly from the directory where the executable is located. How can I achieve this? (translated)
1 Reply
Prisma AI Help
Prisma AI Help5mo ago
You've gone full bot mode! Let me fetch that AI answer for you ASAP. The issue you're facing is common when distributing Prisma-based Node.js apps as executables: Prisma Client expects the query engine DLL (e.g., query_engine-windows.dll.node) in specific locations, and if it can't find it, you'll get errors. To solve this, you can explicitly tell Prisma Client where to find the engine DLL by setting the environment variable PRISMA_QUERY_ENGINE_LIBRARY to the path where the DLL is located. In your case, you want it to load from the same directory as your executable. Here's how you can do it in your Fastify app before initializing PrismaClient:
const path = require('path');

// Set the engine path to the directory of the executable
process.env.PRISMA_QUERY_ENGINE_LIBRARY = path.join(
path.dirname(process.execPath),
'query_engine-windows.dll.node'
);

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const path = require('path');

// Set the engine path to the directory of the executable
process.env.PRISMA_QUERY_ENGINE_LIBRARY = path.join(
path.dirname(process.execPath),
'query_engine-windows.dll.node'
);

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
This approach ensures that Prisma always looks for the DLL next to your executable, regardless of the working directory or folder structure. Make sure to copy the DLL to the same directory as your executable when distributing it. This method is documented and supported by Prisma for custom engine locations using the PRISMA_QUERY_ENGINE_LIBRARY environment variable. You can set this variable in your code or via a .env file or system environment variable, but setting it programmatically as above is most reliable for executables that may run from different locations Custom engine file locations. If you use the binary engine instead of the library, use PRISMA_QUERY_ENGINE_BINARY instead, but for most recent Prisma versions, the Node-API library (.dll.node) is the default. Note: You must ensure the DLL is present in the same directory as the executable when you distribute your app. There is no built-in way for Prisma to automatically look in the executable's directory unless you set the environment variable as shown above. ✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?