Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular project can't find package: src - Solved #738

Closed
linhub15 opened this issue Oct 23, 2018 · 6 comments
Closed

Angular project can't find package: src - Solved #738

linhub15 opened this issue Oct 23, 2018 · 6 comments

Comments

@linhub15
Copy link

For anyone that runs into this issue.
Using absolute paths for Typescript import statements causes project to give an error.
It works fine in VS Code locally, but not on Stackblitz.

image

Wrong: absolute importimport { Employee } from 'src/app/models/employee.model';
Right: relative imports import { Employee } from '../models/employee.model';

I'm new to Angular so I'm not sure what the best practices are.

@EricSimons
Copy link
Member

@linhub15 does it also work w/ the Angular CLI? I think we disabled absolute paths bc it wasn't supported in the newer versions of Ang CLI, but can investigate otherwise

@linhub15
Copy link
Author

No need to enable absolute paths in Angular, I think this is more of a Typescript / Javascript file import thing.
Most Angular CLI commands & options only use relative paths.

  1. Angular Docs: Strongly encouraged to only write component-relative paths
    • refers to this I believe
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',   <--- is relative
  styleUrls: ['./app.component.css']     <--- also relative
})
  1. Angular Docs: Angular CLI options can be either relative or absolute
    • refers to ng g c /path/myComponent --my-option 'C:\documents\more\absolute\paths'

Argument for absolute paths

src
└─app
   ├─core
   |   └─services
   |      └─api.service.ts
   └─features
       └─feature1
          └─employee.component.ts

EmployeeComponent imports the ApiService
import { ApiService } from '../../../core/services/api.service';
import { ApiService } from 'src/app/core/services/api.service'; // Configure tsconfig.json

Projects with deep directory structures benefit from absolute import paths.
I see you're already dealing with this in Issue #139, this issue might be duplicate.

@amit-kumar-dubey
Copy link

yes i have the same issue and it resolved by adding relative path.
thanks

@reza3zar
Copy link

reza3zar commented Oct 7, 2019

but it doesn't work me!!!

@wallysoncarvalho
Copy link

Still having this problem, any ideia how to fix ?

@HemanthGirimath
Copy link

I did try the relative path. But its not working still the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants