Express & Typescript - Importing local modules with multiple ts-configs

Viewed 20

I'm modularising my code to split my oauth routes into a seperate typescript file in a sibling folder. I'm not sure what I'm doing wrong when trying to import from a seperate folder. On ts-node run its unable to find the authRoutes.ts.

My set up is have 3 seperate ts-configs, one is in the root of the workplace which has all the main settings I need whilst I have 2 seperate ts-config files in the /src/routes and /src/ts folder that extends from the root with the only difference being the outDirs in each of the 2.

I've tried setting up the /src/routes path as a "path:" setting in the root ts-config with the same error when trying to run ts-node. Below is my folder structure and my root ts-config both other ts-config file uses to extend.

import authRoutes from "../routes/authRoutes";
app/
├─ public/
│  ├─ css/
│  ├─ js/
│  ├─ routes/
├─ src/
│  ├─ routes/
│  │  ├─ tsconfig.json
│  │  ├─ authRoute.ts
│  ├─ scss/
│  ├─ ts/
│  │  ├─ tsconfig.json
│  │  ├─ app.ts
├─ views/
tsconfig.json
{
  "include": ["src/**/*"],
  "compilerOptions": {
    "target": "es2022",
    "module": "es2022",
    "composite": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "ts-node": {
    "esm": true
  },
  "references": [
    { "path": "./src/ts/tsconfig.json" },
    { "path": "./src/routes/tsconfig.json" }
  ]
}
0 Answers
Related