1

My Angular 6 project with TypeScript version "2.7.2" has tsconfig.json as

{ "compileOnSave": false, "compilerOptions": { "baseUrl": "./src", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2017", "dom" ] }, "paths":{ "@services/*": ["app/services/*"] } } 

I tried importing a service using the above path

 import { AppService } from '@services/app.service'; 

But I'm getting this error on running ng serve

ERROR in src/app/app.module.ts(20,26): error TS2307: Cannot find module '@services/app.service'.

P.S.- Without the paths

import { AppService } from './services/app.service'; 

is working fine.

1 Answer 1

3

paths option is part of compilerOptions

{ "compileOnSave": false, "compilerOptions": { "baseUrl": "./src", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2017", "dom" ], "paths":{ "@services/*": ["app/services/*"] } }, } 
Sign up to request clarification or add additional context in comments.

1 Comment

It was that simple. I feel so stupid missing that. Thanks a lot mate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.