-->

How to set paths property in a project with multip

2020-08-14 07:54发布

问题:

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'

回答1:

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.