Home > Blockchain >  How should I import components inside the components folder?
How should I import components inside the components folder?

Time:10-23

I have some files in my components folder. Two of them are CardItem-component/CardItemComponent.js and list-component/list-components.js. When I'm trying to import the first component into the latter using

import CardItemComponent from "./CardItem-component/CardItemComponent";

it gives the following mistake:

Module not found: Error: Can't resolve './CardItem-component/CardItemComponent' in 'D:\project\src\components\list-component'

CodePudding user response:

import CardItemComponent from "./CardItem-component/CardItemComponent";

CodePudding user response:

Make sure you have given the correct file path and exported the component

export default CardItemComponent 

CodePudding user response:

Based on your explanation of your file structure, maybe you are targeting the wrong directory.

import CardItemComponent from "../CardItem-component/CardItemComponent";

I'm guessing your file structure is:

  • /some-folder
    • /CardItem-component
      • CardItemComponent.js
    • /list-component
      • list-components.js

When you are importing CardItemComponent.js from list-components.js, you need to go up one directory level to access the /CardItem-component folder, so you will need to prepend your path with ../.

  • Related