Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  104] [ 4]  / answers: 1 / hits: 49062  / 7 Years ago, mon, february 13, 2017, 12:00:00

I have such project structure:



- MyApp
`- firstFolder
`- firstFile.js
`- secondFolder
`- thirdFolder
`- thirdFile.js


How can I import firstFile.js from thirdFile.js?



Something like import myFunc from '../firstFolder/firstFile'; in thirdFile.js, doesn't work.


More From » requirejs

 Answers
172

Description


Here are the pathing options (relative path):


../ will go back 1 folder, this is why we go back two folders:


import myFunc from ../../firstFolder/firstFile

So .. takes us back to secondFolder then we need to go back one more folder .. into the MyApp folder. Now we can traverse forward into firstFolder then point to firstFile.


or ./ - this is the present working directory (pwd), which will be thirdFolder from here we will need to go back 2 directories or ../..


import myFunc from ./../../firstFolder/firstFile

Other directory pathing options (full path):


Since you didn't specify the full paths these are incomplete


/ - will start at the root directory of the Operating System


import myFunc from /fullPathtoProject/MyApp/firstFolder/firstFile

~/ this is the current users home directory


import myFunc from ~/pathFromHomeDirectory/MyApp/firstFolder/firstFile

[#58954] Friday, February 10, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nikoguym

Total Points: 339
Total Questions: 106
Total Answers: 95

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
nikoguym questions
Wed, Sep 22, 21, 00:00, 3 Years ago
Sun, Dec 13, 20, 00:00, 4 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
;