Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng serve can't resolve imports from src path, but work when using relative path

Tags:

angular

when importing something using src\app... angular cli gives error " Module not found: Error: Can't resolve 'src/app/shared/k/k-api.service' in 'C:...' ". error TS2307: Cannot find module 'src/app/shared/k/k-api.service'

import { KAPIService } from 'src/app/shared/k/k-api.service';

but when using relative path it works just fine

import { KAPIService } from '../../../../shared/k/k-api.service';
like image 568
tamim abweini Avatar asked Feb 03 '19 09:02

tamim abweini


1 Answers

I managed to solve it by changing "baseUrl": "./", to "baseUrl": "./src", in tsconfig.json then

import { KAPIService } from 'app/shared/k/k-api.service';

not sure if this is the best solution, but works for me.

like image 106
tamim abweini Avatar answered Sep 29 '22 23:09

tamim abweini