Reactjs 如何将文件导入到3个文件夹中
我正在编辑一个文件Product.jsx,文件路径为:Reactjs 如何将文件导入到3个文件夹中,reactjs,Reactjs,我正在编辑一个文件Product.jsx,文件路径为:src\components\Products\Product\Product.jsx 我想导入一个CartContext文件,路径为:src\context\CartContext.js 我正在尝试这样做:import{CartContext}来自“../../../context/CartContext” 要导入它,但我得到错误: Failed to compile ./src/components/frontpage/Product.j
src\components\Products\Product\Product.jsx
我想导入一个CartContext文件,路径为:src\context\CartContext.js
我正在尝试这样做:import{CartContext}来自“../../../context/CartContext”代码>
要导入它,但我得到错误:
Failed to compile
./src/components/frontpage/Product.js
Module not found: You attempted to import ../../../context/CartContext which falls outside of the project src/ directory.
Relative imports outside of src/ are not supported.
我从来没有导入错误,也不知道发生了什么
自动导入也不起作用。结果表明我编辑了错误的文件,该文件位于src\components\frontpage\Product.js中,导致“不在项目src/目录范围内”错误。该错误表明有问题的文件位于/src/components/frontpage/Product.js
,您在构建过程中是否移动了文件而不是src\components\Products\Product\Product.jsx
?非常感谢,您救了我。我正在制作一个新的产品文件,但我没有意识到旧的文件是一个窃听器。这是一个快速解决方案