Satish Patro
Satish Patro

Reputation: 4424

Angular can't find module local file

In my application, in various component I called SharedService

but ts error can't find module Sharedservice when

import { SharedService } from 'src/app/shared/shared.service';

even Path Intellisense is pointing properly

But, when I changed to relative

import { SharedService } from '../app/shared/shared.service';

Is there any place where it is need to be written to point to src/...

Upvotes: 1

Views: 1090

Answers (2)

Tony Brasunas
Tony Brasunas

Reputation: 4611

Ensure you have the baseUrl properly set

If you're using paths in your tsconfig.json or tsconfig.app.json, you need to also configure the baseUrl property in the same file.

Most commonly, this baseUrl property should be updated from ./ to src.

Upvotes: 1

Prasanth
Prasanth

Reputation: 537

I think you need to configure your tsconfig.json as follows,

  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "components/*":  [ "app/components/*" ],
      "services/*":  [ "app/services/*" ],
      "shared/*":  [ "app/shared/*" ]
    },

You can do import as follows

import { SharedService } from 'shared/shared.service';

Upvotes: 0

Related Questions