How to force-include a specific dependency (Prisma CLI) in standalone build?
Answered
Gray Jay posted this in #help-forum
Gray JayOP
I've been banging my head against this for most of the day: I'm running my Next.js + Prisma app in Docker and have my Dockerfile set up similar to the https://github.com/vercel/next.js/tree/canary/examples/with-docker example. I've also added the prisma CLI to my
dependencies, but Next.js will not include it in the final standalone build because it's not used directly in the code of my app. I need it to run migrations during server startup though (and would also like to occasionally run Prisma Studio from the same image by overriding the docker entrypoint). Is there a way to force Next.js to include the prisma dependency in a standalone build? I explicitly don't want to use npx here because that implies downloading the prisma dependency (and any necessary engine binaries) during runtime which is too fragile IMHO. I want to have everything baked into the final Docker image.Answered by joulev
so to summarise, use
*
*
*
outputFileTracingIncludes with*
./node_modules/prisma/**/**
./node_modules/@prisma/**/**
./node_modules/.bin/**/*21 Replies
@Gray Jay I've been banging my head against this for most of the day: I'm running my Next.js + Prisma app in Docker and have my Dockerfile set up similar to the https://github.com/vercel/next.js/tree/canary/examples/with-docker example. I've also added the prisma CLI to my `dependencies`, but Next.js will not include it in the final standalone build because it's not used directly in the code of my app. I need it to run migrations during server startup though (and would also like to occasionally run Prisma Studio from the same image by overriding the docker entrypoint). Is there a way to force Next.js to include the `prisma` dependency in a standalone build? I explicitly don't want to use `npx` here because that implies downloading the `prisma` dependency (and any necessary engine binaries) during **runtime** which is too fragile IMHO. I want to have everything baked into the final Docker image.
try
outputFileTracingIncludes https://nextjs.org/docs/app/api-reference/next-config-js/output#caveatsGray JayOP
My understanding is that this just emits a .nft.json file which is not used at the moment?
Currently, Next.js does not do anything with the emitted .nft.json files. The files must be read by your deployment platform, for example Vercel, to create a minimal deployment. In a future release, a new command is planned to utilize these .nft.json files.
if a whole option was added and documented only to spit out a useless file, it would be a bit weird, wouldn't it?
but basically in the caveat section, there are three bullet points.
outputFileTracingIncludes is the second bullet and .nft.json is the thirdso no, they are not related.
anyway, try it
Gray JayOP
Absolutely. This will not let me specify specific packages though, only files to include. Will try it with a file which basically just does
import prisma.i think you can do
'./node_modules/prisma/**/*'Gray JayOP
Ok, that seems to have worked to a degree. At least, the prisma dependency is now included in the generated
node_modules folder. But npx prisma doesn't find prisma and running the CLI manually via ./node_modules/prisma/build/index.js gives me missing dependencies Cannot find module '@prisma/engines'. Feels … hacky, tbh.I'll try including
./node_modules/@prisma/**/* as well.Works. At least with
node ./node_modules/prisma/build/index.js which could break at any time, I guess. Wonder why npx doesn't find the prisma dependency…how do you run
npx?i think you need to run it inside the standalone folder
npx pretty much just looks up the file in the node_modules/.bin directory... WAITyeah, copy
node_modules/.bin as wellthen
npx probably will workGray JayOP
Good idea
Yay, that worked! Thanks a lot! 🎉
glad it worked
so to summarise, use
*
*
*
outputFileTracingIncludes with*
./node_modules/prisma/**/**
./node_modules/@prisma/**/**
./node_modules/.bin/**/*Answer
Gray JayOP
I summarized everything in a Gist as well:
https://gist.github.com/soulchild/1b073fea3dd76a1a1978ff2a6adf85e7#file-next-config-js
https://gist.github.com/soulchild/1b073fea3dd76a1a1978ff2a6adf85e7#file-next-config-js