简体   繁体   中英

Module Not Found React Js

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

i am getting the above error when i am trying to rum my react app. I was learning and a beginner at react js. i was learning about mapping in reactjs and when i run my app i am getting this error anyone please solve this.

the file system allocation is below.

文件系统语法

Use import App from "./components/App" instead of import App from "../components/App";

../ means that you want to go out from the folder in which your file is. that means that ../ takes you under mapping so you import like this

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

but it is better to not go out and use ./ to stay under src and import like this:

import App from "./components/App"

both are correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM