[英]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:我的 React 项目中有一个文件夹系统,您可以在下面的屏幕截图中看到:
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
.我正在尝试从位于
src/context.js
的文件context.js
导入位于src/components/KeyboardCard/index.js
index.js
index.js 。
I am getting this error message:我收到此错误消息:
Module not found: Can't resolve '.../context.js' in 'C:\React\top-board\src\components\KeyboardCard'.
找不到模块:无法解析“C:\React\top-board\src\components\KeyboardCard”中的“.../context.js”。
Help me please.请帮帮我。
You can't have triple dots import there, try:你不能在那里导入三重点,试试:
import AppContext from '../../context.js';
It's two levels higher:它高了两个级别:
import AppContext from '../../context';
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:如果你想 go 高 2 级,你必须这样做:
../../context
Also, you don't have to define file format ".js" there, that's not required.此外,您不必在那里定义文件格式“.js”,这不是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.