简体   繁体   English

找不到模块 React Js

[英]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.当我尝试朗读我的 React 应用程序时出现上述错误。 I was learning and a beginner at react js.我正在学习并且是 React js 的初学者。 i was learning about mapping in reactjs and when i run my app i am getting this error anyone please solve this.我在 reactjs 中学习映射,当我运行我的应用程序时出现此错误任何人都请解决这个问题。

the file system allocation is below.文件系统分配如下。

文件系统语法

Use import App from "./components/App" instead of import App from "../components/App";使用import App from "./components/App"而不是import App from "../components/App";

../ means that you want to go out from the folder in which your file is. ../表示您想从文件所在的文件夹中取出 go。 that means that ../ takes you under mapping so you import like this这意味着../带您进行mapping ,因此您可以像这样导入

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

but it is better to not go out and use ./ to stay under src and import like this:但最好不要 go 出来并使用./留在src下并像这样导入:

import App from "./components/App"

both are correct.两者都是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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