The project was generated via angular CLI. I have the following folder structure:
I want to define a path to a bar folder in tsconfig.app.json and import Car
to Garage
.
My tsconfig.app.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
...
"baseUrl": "./",
"paths" : {
"@bar" : ["foo/bar"]
},
...
},
...
}
My Garage.ts:
import { Car } from "@bar/Car";
export class Garage {}
In garage.ts I have an error:
Cannot find module '@bar/car'.
You need to define paths
like that:
"paths" : {
"@bar/*" : [
"foo/bar/*"
]
},
For more information read
Please do not forget to put the baseUrl
first before adding the paths
. I spent hours trying to figure out where I was wrong.
"baseUrl": "./",
"paths": {
...
}
I think this might work
{
"extends": "../tsconfig.json",
"compilerOptions": {
...
"baseUrl": "./",
"paths" : {
"@bar" : ["foo/bar"],
"@environment/*": ["environments/*"],
"@shared/*": ["app/_shared/*"],
"@helpers/*": ["helpers/*"]
//you can define multiple paths inside this
},
...
},
...
}
and the question looks like duplicate of question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With