Absolute imports not working in typescript

34 Views Asked by At

I have the following folder structure:

- src
--- entities
----- index.ts
----- Address.ts
--- initializers
----- getLoaders.ts

I would like to be able to run import {Address} from "entities" in the getLoaders.ts file. However I get the error: Error: Cannot find module 'entities'

My tsconfig.json is:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "lib": [
      "dom",
      "es6",
      "es2017",
      "esnext.asynciterable"
    ],
    "skipLibCheck": true,
    "sourceMap": true,
    "outDir": "./dist",
    "moduleResolution": "node",
    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "baseUrl": "./src",
    "paths" : {
    },
    "typeRoots": [
      "./src/custom_typings",
      "./node_modules/@types",
    ],
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "src/**/*.ts",
    "**/*.ts"
  ]
}

entities/index.ts contains the line export { Address } from "./Address"

If I run import {Address} from "../entities" I get no problems.

I have tried to copy the approaches of various tutorials but have not been able to fix this issue... How can I fix this to enable absolute imports?

0

There are 0 best solutions below