Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set paths property in a project with multiple tsconfig.json?

I have the following file structure

|__ app1/
|   |__ tsconfig.json
|__ utilities/
|   |__ files.ts
|__ base-tsconfig.json

In base-tsconfig.json I have set the paths property as following

"compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "utils/*": ["utilities/*"]
        }
}

and in tsconfig.json it looks as follow

{
    "extends": "../base-tsconfig",
}

That should be enough right? I am still getting below message though.

Cannot find module 'utils'

like image 670
starcorn Avatar asked Jun 29 '18 09:06

starcorn


People also ask

Can you have multiple Tsconfig json files?

You could use multiple tsconfig files to solve some of those problems, but new ones would appear: There's no built-in up-to-date checking, so you end up always running tsc twice.

What should I put in Tsconfig json?

The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.

What is allowJs Tsconfig?

allowJs is the option newly available in 1.8. The TypeScript compiler will run a quick sanity check on . js files for syntax errors but otherwise passes them straight through to the output directory.


1 Answers

The "paths" option can be used to inform the compiler of mappings but it does not perform these path transformations by itself. You can read more about this in the docs and in this issue. Most likely you are using a loader which does not allow remapping, such as Node.js's require().

There are packages available to help resolve this problem such as module-alias and tsconfig-paths.

like image 107
Zwiers Avatar answered Sep 22 '22 14:09

Zwiers