Тимур
Тимур

Reputation: 25

React import problem, 'Module not found: Can't resolve'

I have a folder system in my React project, which you can see in the screenshot below:

enter image description here

I am trying to make import to index.js, located in src/components/KeyboardCard/index.js, from file context.js that is located in src/context.js.

enter image description here

I am getting this error message:

Module not found: Can't resolve '.../context.js' in 'C:\React\top-board\src\components\KeyboardCard'.

Help me please.

Upvotes: 0

Views: 3175

Answers (4)

Hidayat Mammadov
Hidayat Mammadov

Reputation: 83

If you want to go 2 levels higher you have to do it like this:

../../context

Also, you don't have to define file format ".js" there, that's not required.

Upvotes: 1

Ayush Gupta
Ayush Gupta

Reputation: 1227

You have provided the wrong path.

import AppContext from '../../context.js';

Upvotes: 2

Adam Jenkins
Adam Jenkins

Reputation: 55623

It's two levels higher:

import AppContext from '../../context';

Upvotes: 2

Ryan Le
Ryan Le

Reputation: 8412

You can't have triple dots import there, try:

import AppContext from '../../context.js';

Upvotes: 2

Related Questions