Module not found monorepo websocket server

Hi guys, I’m trying to deploy my Turborepo app. The folder structure looks like this:

├── apps
│├── frontend (vite)
│├── backend (express)
│├── ws (websocket server)
├── packages
│├── db (prisma client) (used by backend and ws server)
│├── messages (exports string values and types for websocket rooms) (used by frontend and ws server)

I’m exporting the packages db and messages and importing them in frontend, backend and ws modules. I was able to deploy the frontend and backend on vercel without any errors and it works fine. However, when I tried deploying the ws directory (websocket server) on render I get this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/opt/render/project/src/node_modules/@instachat/db/src/index.js' imported from /opt/render/project/src/apps/ws/dist/managers/InboxManager.js

I’m exporting and importing the packages/db module into ws directory the same way I’m doing it in backend (express server) directory. There was an option in vercel that allows inclusion of files outside the root directory and I ticked that. Is there something similar on render as well? How do I resolve this issue?

Code snippets:

apps/ws/package.json: pastecord
packages/db/package.json: pastecord

Hi there,

A few things to look into:

  1. Are you trying to run a frontend, backend, and web socket app all within a single service? If so, we really don’t recommend this. Instead, break these all up into separate individual services, each with its own streamlined configuration.
  2. Be sure to check the Events page (or the top of any failed build log) for a reason Render may surface as a potential cause of the failed deploy.
  3. MODULE_NOT_FOUND errors like this are often caused because the referenced file either doesn’t exist in the location specified, or there is some kind of casing mismatch or spelling typo. Sometimes we see a discrepancy between a user’s local environment and what’s actually checked into the repository being used by Render.

If none of these suggestions lead to a solution, I recommend reaching out to us privately via the Contact Support link in the Dashboard so we can take a closer look at your service. In this event, please be sure to specify the service (by name or id) that you are referring to.

Regards,
Mike


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)

Hey Mike, thanks for the reply. I tried finding the solution on google and AI but nothing helped. Went back to the turborepo docs and had a deeper dive and finally figured out how to make it work. Basically the monorepo packages that I was trying to use were not getting installed. Couple of reasons why:

  1. I was exporting the internal packages the wrong way. So fixed that.
  2. Building the packages first before building the app by specifying it in the turbo.json (although I think it was building the packages first anyway)

So glad you were able to find a solution! Thanks so much for sharing it with the community.

Hope you have a great weekend!

Regards,
Mike


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.