簡體   English   中英

React - 找不到模塊 - 好像目錄不存在

[英]React - Module not found - As if the directory didn't exist

我是反應的初學者,我根本無法解決這個錯誤。 我不知道該怎么做,我試圖重新創建,尋找答案,這個錯誤總是出現,好像目錄不存在一樣。

有人能幫我嗎?

錯誤:

Failed to compile
./src/components/MenuComponent.js
Module not found: Can't resolve './components/DishDetailComponent'

菜單組件.js

import React, { Component } from 'react';
import { Card, CardImg, CardImgOverlay, CardText, CardBody, CardTitle } from 'reactstrap';
import DishDetail from './components/DishDetailComponent';

class Menu extends Component {

    constructor(props) {
        super(props);

        this.state = {
            selectedDish: null
        };
    }
    ...
}

export default Menu;

DishDetailComponent.js

import React, { Component } from 'react';

class DishDetail extends Component {

    constructor(props) {
        super(props);
    }

    render(){
        return(
            <div></div>
        );
    }
}

export default DishDetail;

文件夾點擊查看圖片

路徑與導入它們的模塊是相對的。 您的兩個文件都在components目錄中,但MenuComponent.js正在嘗試從./components/DishDetailComponent導入,這實際上會導致./components/components/DishDetailComponent

將您的導入更改為./DishDetailComponent應該沒問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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