question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular project `can't find package: src` - Solved

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:16
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
linhub15commented, Oct 24, 2018

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.

1reaction
reza3zarcommented, Oct 7, 2019

but it doesn’t work me!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't find package src in StackBlitz after installing dependencies
"Using absolute paths for Typescript import statements causes project to give an error. It works fine in VS Code locally, but not on...
Read more >
Creating libraries - Angular
This page provides a conceptual overview of how to create and publish new libraries to extend Angular functionality. If you find that you...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Cannot find module '@angular-devkit/build-angular ... - YouTube
... occurred: Cannot find module '@ angular -devkit/build- angular / package.json'The above exception while running an angular app can be handl.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found