npm 未找到模块React Js

vzgqcmou  于 2023-01-09  发布在  React
关注(0)|答案(2)|浏览(218)
Failed to compile.

Module not found: Error: You attempted to import ../components/App which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.
ERROR in ./src/index.js 6:0-36
Module not found: Error: You attempted to import ../components/App which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.

webpack compiled with 1 error

我得到上述错误时,我试图运行我的react应用程序。我正在学习和初学者在react js。我正在学习Map在reactjs和当我运行我的应用程序,我得到这个错误的任何人请解决这个问题。
文件系统分配如下。

bq3bfh9z

bq3bfh9z1#

使用import App from "./components/App"代替import App from "../components/App";

7vhp5slm

7vhp5slm2#

../意味着你想从你的文件所在的文件夹中退出.这意味着../将你带到mapping下,所以你像这样导入

import App from "../src/components/App"

但最好不要出去使用./,而是停留在src下,并像这样导入:

import App from "./components/App"

都是对的。

相关问题