Command to build/run typescript project with NX
Asked Answered
T

0

8

I am trying to run typescript file (within an app) that depends on a couple libraries with NX but I can not figure out how to do it. I've tried numerous methods, here are a couple ways I tried:

First Try

  "cron": {
      "executor": "nx:run-commands",
      "options": {
            "command": "ts-node apps/src/cron.ts"
      }
    },

I get the following error:

node:internal/modules/cjs/loader:959
  throw err;
  ^

Error: Cannot find module './cron.ts'
Require stack: ...

Second Try

I've also tried the following:

"build": {
      "executor": "@nrwl/js:tsc",
      "outputs": ["{options.outputPath}"],
      "options": {
        "platform": "node",
        "target": "node14",
        "outputPath": "dist/apps/cron",
        "tsConfig": "apps/cron/tsconfig.app.json",
        "main": "apps/crons/src/cmd/run-token-trade-counts-cron.ts"
      }
    },

This time it manages to compile correctly, but i get the following error when I run the executable:

nx run cron:cron

Error: Cannot find module '@company/logger'

What am I doing wrong ?

Thank you

Trapes answered 19/8, 2022 at 17:9 Comment(1)
I'm facing a very similar issue, did you end up finding a solution ?Plashy

© 2022 - 2024 — McMap. All rights reserved.