#monorepo mode --watch is not working

80 messages · Page 1 of 1 (latest)

wheat kettle
#

hey y'all, I have a super simple application

import { NestFactory } from '@nestjs/core'
import { Logger } from 'nestjs-pino'
import { CrawlerModule } from './crawler.module'

async function bootstrap() {
const app = await NestFactory.createApplicationContext(CrawlerModule)
// logging
app.useLogger(app.get(Logger))
app.flushLogs()

app.enableShutdownHooks()
}
bootstrap()

and when I change crawlerModule it will refresh but it won't rebuild dist so the added code isn't actually getting hot reloaded.

wheat kettle
#

@past viper sorry to tag direct, you're my bestie though and always have a good answer.

#

I'm thinking about using nx instead of monorepo

past viper
#

I will personally always advocate for the use of Nx over Nest's monorepo mode. The fact that it will handle 99% of your needs out of the box is incredible. I ended up building a few custom executors for running things like biome or how I wanted to re-use a docker build step for most of my apps, but overall it's a pretty solid example of how a monorepo can be used

#

@shell python is a big advocate for Rush as well, if you want another monorepo tool to look at

wheat kettle
#

@past viper all I need right now is to be able to access each other's apps code (i don't have time to turn every module into a shared lib) and hot reload / re-build

#

I have monorepo almost working but for some reason it's not rebuilding the code just "reloading" the same dist

#

@past viper what I don't understand is you don't have any scripts in your package.json -- how do you run watch vs start

#

nest --watch vs next -- start

past viper
#

pn nx run server:serve (and similar for the other apps)

#

pn being an alias for pnpm

wheat kettle
#

okay going to copy your nx.json and package.json's and hope for best

#

how do you have hot reload working -- is that what swc is for?

past viper
#

I feel like you're about to jump down a rabbit hole and have a bunch of questions without really understanding why you're doing what you're doing

#

So let's take a step back before jumping into Nx

#

What's the current situation

wheat kettle
#

righrt now I have a productionize (dockerfile) const app = await NestFactory.create(AppModule, appOptions) running on ECS

#

I have a ton of modules and code that should be shareable between some other services -- in fact -- I already have a lot of this other service coded but I want to move it into this same repository to share some modules (db modules etc)

#

so I want to create a new service (non-api) that shares some of those modules and services.

#

that will be deployed as a separate ecs instance

#
crawler:
    platform: linux/arm64
    build:
      dockerfile: Dockerfile
      context: .
      target: development
      args:
        NPM_AUTH_TOKEN: ${NPM_AUTH_TOKEN}
    env_file: .env.development.local
    volumes:
      - .:/usr/src/app
    command: yarn start:crawler-dev
    depends_on:
      - postgres
    networks:
      - backend

this is in my docker-compose for the new microservice and it works well besides the re-building issue mentioned above.

past viper
#

Is it possibly not rebuilding due to a docker caching issue?

wheat kettle
#

if i do npx build crawler and then do a hot reload it works

#

so it's not re-building the .dist/ like the .js files are not changing

past viper
#

Is it the docker instance that isn't hot reloading here?

wheat kettle
#

btw you have your nx cloud token in your nx.json file -- not sure if that gives access to anything but just a heads up

past viper
wheat kettle
#

cool

#

the docker instance actually reloads -- like you see it say crawler-1 | [10:09:15 PM] Found 0 errors. Watching for file changes.

#

but it just reruns the same code (./dist isn't rebuilding)

past viper
#

So most likely the context isn't being updated, even though you have a volume set

#

I don't use docker for local development, jsut a docker-compose for running services I need, db, rabbet, redis, etc

#

Everything else I run on my local machine during dev, and then set up a working docker-compose that can be deployed

wheat kettle
#

so what do you use for hot reload in that github above @past viper ?

past viper
#

That same command I showed above.

wheat kettle
#

server:serve?

past viper
#

Yep. @nx/js:node, by default, has hot reloading setup

wheat kettle
#

blah i just want the monorepo mode to rebuild

#
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "apps/pursuit/src",
  "monorepo": true,
  "root": "apps/pursuit",
  "watchAssets": true,
  "compilerOptions": {
    "webpack": true,
    "tsConfigPath": "tsconfig.json"
  },
  "projects": {
    "pursuit": {
      "type": "application",
      "root": "apps/pursuit",
      "entryFile": "main",
      "sourceRoot": "apps/pursuit/src",
      "compilerOptions": {
        "tsConfigPath": "apps/pursuit/tsconfig.app.json"
      }
    },
    "crawler": {
      "type": "application",
      "root": "apps/crawler",
      "entryFile": "main",
      "sourceRoot": "apps/crawler/src",
      "compilerOptions": {
        "tsConfigPath": "apps/crawler/tsconfig.app.json"
      }
    }
  }
}```
this is my nest-cli.sjon
#

i don't think it's the docker context that's not updating

past viper
#

Are you running your crawler server locally or in a docker image?

wheat kettle
#

docker

#

but cat dist/apps/crawler/src/crawler.module.js doesn't get updated until i run nest build

past viper
#

So yeah, my bet would be in docker being the issue here.. If you were to try locally, I'd almost bet it works as you'd expect

wheat kettle
#

same issue

#

with npx nest start crawler --tsc --watch outside of docker

past viper
#

Then can you make a reproduction I can run locally to see this?

#

I don't use nests monorepo mode, so I'd need something to work with

wheat kettle
#

ok

#

can i dm it to you?

past viper
#

If you need to

wheat kettle
#

so basically if you run yarn and npx nest start --tsc --watch this will work w/ the default app and oyu can change the console.log in the app.module and see it refresh

#

if you run npx nest start crawler --tsc --watch you can see it not work when you change consoel log

#

semi - got it to work w/ npx nest start crawler --tsc --watch -b webpack

wheat kettle
#

ok

#

i give up

past viper
#

I'll see what I can do. I'd really rather a git repo over a zip file though

wheat kettle
#

😦

shell python
#

Am I understanding that your issue is the updates in a dependency aren't updating in your app?

wheat kettle
#

it's all messed up and broken is what the issue is

#

but i'd love to use nx

viral coral
#

@wheat kettle I am trying to configure monorepo using nx. I have some cache problems when running projects with nextjs, nestjs. please help me fix this error .

glad badge
shell python
shell python
wheat kettle
#

@shell python @past viper can I pay y'all for hour of your time to help me setup a mono repo?

shell python
#

What repo manager do you wish to use? Nx or Rush? Or some other?

wheat kettle
#

None right now @shell python

shell python
#

@wheat kettle - Well, look at the different options and choose one. 🙂

wheat kettle
#

@shell python haha I know you're a rush advocate, want to hop on a call and set it up? Will pay you your hourly rate -- desparate at this point 😓

shell python
#

I'm not a total expert in any of it. So, not sure I can be worth your paying me to be honest. What is the reason for needing the monorepo?

wheat kettle
#

right now I'm deploying on ECS my nest js backend which is a Worker & API combined in one

#

I really would love to make it a mono repo so that I can split it out and deploy them separately but use the same code

#

since they all share service / models

wheat kettle
#

@past viper Jackie 🙂 ?

past viper
#

My life doesn't provide me the time to help with setting up a project or help with consulting work, but you can take a look at my side project to see how I set up my NX monorepo with an API, CLI, image processing server, and UI all in the same repository

shell python
wheat kettle
#

no unfortunately