6

I have a monorepo with Lerna and typescript with a basic structure

- root 
  package.json
  - packages
      package-A
         package.json
         src
      package-B
         package.json
         src

The root package.json tsconfig configuration

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "paths": {
      "@namespace/*": [
        "packages/*/src"
      ]
    },
    "esModuleInterop": true,
    "skipLibCheck": true,
    "types": [],
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

The tsconfig of each package looks like

{
  "extends": "../../tsconfig.json",
  "include": ["src/**/*.ts"],
  "compilerOptions": {
    "outDir": "./dist",
    "rootDir": "./src",
    "baseUrl": "."
  }
}

Now when I run lerna bootstrap or lerna boostrap --hoist all dependencies from package A and package B go to the root module. No node_modules folder gets generated at the packages level.

Is this the normal behaviour?

Also in development, in the packages I have a nodemon script which runs ts-node -r tsconfig-paths/register ./src/index.ts

When I run nodemon directly from the command line, I get

sh: ts-node: command not found
[nodemon] failed to start process, "ts-node -r tsconfig-paths/register ./src/index.ts" exec not found

But when I add it as a script to the packages's package.json "start:dev": "nodemon" and I do npm run start:dev then it works.

It's like in a way nodemon complains about not finding the binary for ts-node in the package's node_modules/.bin (since it's not generated), but when I run it with start:dev it fetches it from the root node_modules..?

Did I miss something in the setup?

AngularDebutant
  • 1,436
  • 5
  • 19
  • 41

0 Answers0