W
Wasp-lang2mo ago
flow

Difficulty deploying via dockerfile to coolify

Trying to deploy my wasp app (which works via netlify/fly.io) to a self-hosted coolify. If I use the dockerfile generated by wasp build with no changes I get module not found errors. The dockerfile will execute, container will start and it processes through, connects to the DB using prisma schema but then: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/node_modules/wasp/dist/universal/validators.js' imported from /app/.wasp/build/server/scripts/validate-env.mjs at new NodeError (node:internal/errors:405:5) at finalizeResolution (node:internal/modules/esm/resolve:327:11) at moduleResolve (node:internal/modules/esm/resolve:946:10) at defaultResolve (node:internal/modules/esm/resolve:1132:11) at nextResolve (node:internal/modules/esm/loader:163:28) at ESMLoader.resolve (node:internal/modules/esm/loader:835:30) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18) at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40) at link (node:internal/modules/esm/module_job:76:36) { code: 'ERR_MODULE_NOT_FOUND' } If I try to build remote - using a dockerfile similar to https://www.koyeb.com/tutorials/using-wasp-to-build-full-stack-web-applications-on-koyeb I cannot get the wasp build process to work due to it not finding the prisma client. Im kind of ambivalent to building locally then deploying or building remotely, but if anyone has tried to deploy to something other than a managed host using a dockerfile, some advice would be appreciated.
6 Replies
kapa.ai
kapa.ai2mo ago
Hi @flow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- It seems like you're encountering issues with module resolution when trying to deploy your Wasp app to a self-hosted Coolify using Docker. While the knowledge sources provided don't specifically address deploying to Coolify, they do offer some insights that might be helpful. Firstly, it's important to note that Wasp currently defaults to using a remote builder when deploying with Docker, as mentioned in the Wasp documentation (https://wasp-lang.dev/docs/advanced/deployment/cli#building-locally). If you want to build locally, you can supply the --build-locally option to wasp deploy fly launch or wasp deploy fly deploy. Regarding the issue with the Prisma client not being found, there was a similar issue reported on Github (https://github.com/wasp-lang/wasp/issues/427) where the Prisma client initialization error occurred on the first start after a clean build. The solution was to manually import the Prisma client and instantiate it:
import { PrismaClient } from './node_modules/.prisma/client'
const prisma = new PrismaClient()
import { PrismaClient } from './node_modules/.prisma/client'
const prisma = new PrismaClient()
After this, running wasp start worked. It was suggested that prisma generate should be checked/run when first building the app at the Node/NPM level. In another Github issue (https://github.com/wasp-lang/wasp/issues/631), a similar problem was solved by changing how Prisma was installed, which avoided the error. If you're still encountering issues, you might want to consider customizing your Dockerfile. A Discord support thread (https://discord.com/channels/686873244791210014/1223671727943319584) discussed how to modify the Dockerfile to copy over a patched file to the built app before deploying it. This might be useful if you need to make specific changes to your build process. Please note that these solutions are based on the provided knowledge sources and might not directly solve your issue. If the problem persists, I would recommend reaching out to the Wasp community or the Coolify support for more specific guidance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @flow, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Filip
Filip2mo ago
Hey @flow, this is strange. Can you maybe share your project?
flow
flow2mo ago
Hey @Filip - I finally stumbled into to something that worked using a build remote approach using this bit at the top of the docker file, I havent debugged what exactly fixed it yet - but I doubt its the version specific install:
FROM node:20 AS base

FROM base AS wasp-builder
WORKDIR /wasp
ADD . .

# Install Wasp
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh
ENV PATH="/root/.local/bin:/root/.npm-global/bin:${PATH}"

RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install
RUN npm install [email protected] @prisma/[email protected]
RUN npx prisma generate
RUN wasp build
FROM node:20 AS base

FROM base AS wasp-builder
WORKDIR /wasp
ADD . .

# Install Wasp
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh
ENV PATH="/root/.local/bin:/root/.npm-global/bin:${PATH}"

RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install
RUN npm install [email protected] @prisma/[email protected]
RUN npx prisma generate
RUN wasp build
Filip
Filip2mo ago
Yeah, I have no idea. @miho Is this familiar to you?
flow
flow2mo ago
the primary issue with build remote is it was struggling finding the prisma client during the wasp build process - so a bit different than just using the dockerfile generated via "wasp build" - either way its working now and I'm thankful for that - once I get things stabilized on my end I may go back and play around with exactly what seems to be altering the build process but if someone else runs into deployment issues & wasp finding the prisma client when building remote maybe this can help them out Thanks for checking in w/ this @Filip
miho
miho2mo ago
Hm, it's pretty strange yes, because this is for example how I built stuff for Caprover (similar to Coolify) - I've built the image in a Github action and then pushed it to Caprover: https://github.com/wasp-lang/deploy-to-caprover-action/blob/main/.github/workflows/deploy.yml I didn't face those kind of error you did. You could do the same with Coolify using the "Existing Docker Image" option.
GitHub
deploy-to-caprover-action/.github/workflows/deploy.yml at main · wa...
Contribute to wasp-lang/deploy-to-caprover-action development by creating an account on GitHub.
No description
Want results from more Discord servers?
Add your server