This seems simple but it doesn't work (for me)
I am running an Angular 5 app that has three files in locations similar to this:
app_directory/tsconfig.json
app_directory/src/app/services/my-service.service.ts
app_directory/src/app/main/sub1/sub2/my-component.component.ts
In the my-component.component.ts file I can successfully import my-service with the following line:
import { MyServiceService } from '../../../services/my-service.service.ts'
While this is all fine and dandy, It's kinda annoying to have to put the relative path every time I want to import this service so I did some checking on SO and I found this post: How to avoid imports with very long relative paths in Angular 2?
So I attempted to do the same thing and changed my tsconfig.json to the following:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src/app/",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
And changed my import to this:
import { MyServiceService } from 'services/my-service.service.ts'
But of course this didn't work. So (without changing the import) I tried the following values for baseUrl:
.
./
./app
./src
./app/
./src/
src/app
src/app/
It seems as though the tsconfig baseUrl has no effect at all. What am I missing here?