最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React import problem, 'Module not found: Can't resolve' - Stack Overflow

programmeradmin0浏览0评论

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

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

I am getting this error message:

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

Help me please.

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

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

I am getting this error message:

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

Help me please.

Share Improve this question edited Aug 14, 2021 at 3:13 rmlockerd 4,1362 gold badges20 silver badges28 bronze badges asked Aug 13, 2021 at 11:32 ТимурТимур 252 silver badges5 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

It's two levels higher:

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

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

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

You have provided the wrong path.

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

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.

发布评论

评论列表(0)

  1. 暂无评论