This may appear straightforward, but I am facing difficulties with it
My Angular 5 application consists of three files located as follows:
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 import my-service successfully using the following line:
import { MyServiceService } from '../../../services/my-service.service.ts'
Although this works fine, it can be tedious to include the relative path every time I need to import this service. I came across a post on SO that discusses this issue: How to avoid imports with very long relative paths in Angular 2?
I decided to implement the same approach by modifying my tsconfig.json as shown below:
{
"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"
]
}
}
I also adjusted my import statement to the following:
import { MyServiceService } from 'services/my-service.service.ts'
Unfortunately, this change did not yield the desired result. I played around with various values for baseUrl without success:
.
./
./app
./src
./app/
./src/
src/app
src/app/
It appears that the tsconfig baseUrl setting is having no impact whatsoever. What could I be overlooking here?