Cannot find module that is defined in tsconfig `paths` Cannot find module that is defined in tsconfig `paths` typescript typescript

Cannot find module that is defined in tsconfig `paths`


I faced the same issue. I tried many things and now i got a solution which works for me. I have an app and a library in my angular project. I want to use a library alias in my app.

I have following structure:

├── projects│   └── lib│       └── src│           └── lib│               └── lib-service.ts│           └── index.ts│   └── app│       └──tsconfig.app.json├── tsconfig.json

In the tsconfig.json file in the root folder I have following paths defined:

"paths": {  "my-lib": [    "projects/lib/src/index.ts"  ]}

There I access an index.ts file where I define the things I want to export. In my case the index.ts file has the following entry:

export * from './lib/lib-service';

Now I can access the LibService in components of the app with the help of the alias:

import {LibService} from 'my-lib';

It is important to mention that this soloution don't work if I add this entry to the tsconfig.app.json file. I think the IDE (in my case WebStorm) searches for aliases in the tsconfig.json file which is close to the root folder. So I extend the tsconfig.json in my tsconfig.app.json

"extends": "../../tsconfig",

Maybe you have to restart you IDE to remove the red underline of the import line.

I hope this solution works for you. You have to to a little bit more of setup work because you have to define the classes you want to export in the index.ts file. But in case of using libraries it make sense because you don't want to make everything visible for other app.


After battling it for some time I figured it out you need to include all directories using tsconfig-paths in your main tsconfig.json. Working version of your tsconfig.json file could be

{    "compilerOptions": {        "baseUrl": ".",...        "paths": {            "@project/app/modules/*": [                "src/modules/*"            ],            "@project/server/data/*": [                "server/src/json/*"            ]        },    },    "include": [        "./src",        "./server"    ],}


The following tsconfig.json worked for me, allowing import { foo } from '@models' etc for the associated index.ts barrel exports:

{    "baseUrl": "./",    "paths": {      "@environment": ["./src/environments/environment.ts"],      "@models": ["./src/app/shared/models/index.ts"],      "@services": ["./src/app/shared/services/index.ts"]    },}