I have the following project structure:
.src
.FolderA
.File3.js
.FolderB
.File2.js
.File1.js
How can I import File1.js from File3.js?
I have tried import ‘../src/File1.js’. But its not working
I have the following project structure:
.src
.FolderA
.File3.js
.FolderB
.File2.js
.File1.js
How can I import File1.js from File3.js?
I have tried import ‘../src/File1.js’. But its not working
2
Answers
Because
../
lands insidesrc
(considering folders and files does not start with.
as in your example), and there is nosrc
folder.Try
../File1.js
Or add alias to your
src
folder, e.g.You need to adjust your import path to correctly navigate the file structure. Here’s how:
Explanation:
..
: This represents going up one level in the directory structure.FolderB
: Navigates to theFolderB
directory.File1.js
: Imports theFile1.js
file withinFolderB
.Example:
Let’s say you have the following file structure:
To import
File1.js
fromFile3.js
: