简体   繁体   English

React - 找不到模块 - 好像目录不存在

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

I'm a beginner in react and I'm not able to resolve this error at all.我是反应的初学者,我根本无法解决这个错误。 I have no idea what to do, I've tried to recreate, look for an answer and this error always appears as if the directory did not exist.我不知道该怎么做,我试图重新创建,寻找答案,这个错误总是出现,好像目录不存在一样。

Can someone help me?有人能帮我吗?

Error:错误:

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

MenuComponent.js菜单组件.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 DishDetailComponent.js

import React, { Component } from 'react';

class DishDetail extends Component {

    constructor(props) {
        super(props);
    }

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

export default DishDetail;

Folder Click for image文件夹点击查看图片

Paths are relative from the module where they are imported.路径与导入它们的模块是相对的。 Both your files are in the components directory, but MenuComponent.js is trying to import from ./components/DishDetailComponent , which actually results in ./components/components/DishDetailComponent .您的两个文件都在components目录中,但MenuComponent.js正在尝试从./components/DishDetailComponent导入,这实际上会导致./components/components/DishDetailComponent

Change your import to be just ./DishDetailComponent and it should be fine.将您的导入更改为./DishDetailComponent应该没问题。

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

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