Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I import file from another directory that is at the same level?

Tags:

typescript

How to import stuff from a file that is in another directory but at the same level? For example: i am in file 1 of folder 1 and want to import stuff from file 2 from folder 2. How to do that? Currently i get the error that the module cannot be found.

Current tree:

-ComponentsFolder
    -Folder1
       -File1
    -Folder2 
       -File2
like image 679
Skatedude Avatar asked Sep 03 '25 02:09

Skatedude


1 Answers

You simply construct relative path from one file to another. Like in in OS.

import '../Folder2/File2';

But you should avoid relative imports because it might get painful really quickly. Consider this: ../../../../dir1/dir2/dir3. Pretty bad, isn't it? There is really good tutorial how to avoid relative paths and use absolute paths. Just a few configuration changes and you get dir1/dir2/dir3 How to avoid imports with very long relative paths in Angular 2?

like image 113
Kacper Wiszczuk Avatar answered Sep 06 '25 21:09

Kacper Wiszczuk