DEV Community

Niclas
Niclas

Posted on

Using ts-node in nx-monorepos

At my current work we use monorepos a lot. We use nx as tool to manage the different projects in the repo.
Naturally you also need some scripts to automate some tasks in the repository. Sometimes you also want to use libraries of your monorepo inside these scripts.

To be able to do that you just need to install tsconfig-paths (npm install -D tsconfig-paths) and alter the ts-config file you use for ts-node:

{
  "extends": "./tsconfig.json",

  ...

  "ts-node": {
    // It is faster to skip typechecking.
    // Remove if you want ts-node to do typechecking.
    "transpileOnly": true,

    "files": true,

    "require": ["tsconfig-paths/register"],

    "compilerOptions": {
      // compilerOptions specified here will override those declared below,
      // but *only* in ts-node.  Useful if you want ts-node and tsc to use
      // different options with a single tsconfig.json.
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The key part is the "require": ["tsconfig-paths/register"] as it enables ts-node to resolve the path of your libraries.

Top comments (0)