[英]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
当我尝试朗读我的 React 应用程序时出现上述错误。 我正在学习并且是 React js 的初学者。 我在 reactjs 中学习映射,当我运行我的应用程序时出现此错误任何人都请解决这个问题。
文件系统分配如下。
使用import App from "./components/App"
而不是import App from "../components/App";
../
表示您想从文件所在的文件夹中取出 go。 这意味着../
带您进行mapping
,因此您可以像这样导入
import App from "../src/components/App"
但最好不要 go 出来并使用./
留在src
下并像这样导入:
import App from "./components/App"
两者都是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.