簡體   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

當我嘗試朗讀我的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM