Reactjs Importing from the same directory
I solved the error Myself, the import should be
Import Task from '../task'
I know the OP solved for OP, but it did not work for me. Here is what I had to do:
import Task from '../components/task'
After little bit of investigation, I found that the project tree starts from the project root, so relative path names have to be traced from the current file location, then traverse up (../
) and down the tree (subdirName/
) to the imported file, if you want to specify relative path. It is also possible to specify absolute path like:
import Task from 'C:/Users/devusr1/source/repos/React/hello-world/src/components/task.js'
Both relative and absolute paths worked for me (I am using nodejs.)
What did not work:
.
./
../components
./src/components/task