Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to import despite clearly having the file

I’ve been stuck with this error and couldn’t fix it even after googling.

it says ‘Module not found: Error: Can’t resolve’.. based on researching on google, it appears that this happens when the import statement cannot find the file at the declared path.

But there clearly is a file named ‘Button.js’ in my src/components folder.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am not sure what is wrong. Would really appreciate your help! enter image description here

>Solution :

A fix you could do is either exporting Button module as default in the end of Button.js file like

export default Button;

Or either import the button module in braces like :

import { Button} from “./components/Button”

If you haven’t set the base url as src:

As you are using relative paths and /components/Button.js is upper than the page directory so you have to use .. to come out of the pages directory and then read /pages/Home.js

So you should use ../Button.js instead of ./componets/Button.js

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading