简体   繁体   English

在React中找不到模块

[英]Module not found in React

I am new to React. 我是React的新手。 I have create new react app using following command. 我已经使用以下命令创建了新的React应用。

create-react-app app-name --scripts-version custom-react-scripts-version

Inside src folder of that app i have created 2 new folders say Grid and Title and created files Grid.js and Title.js in respected folder. 在该应用程序的src文件夹中,我创建了2个新文件夹,分别为GridTitle ,并在受尊重的文件夹中创建了文件Grid.js和Title.js。

Grid.js Grid.js

import React from 'React';

export default class Grid extends React.Component {
    render() {
        return (
            <div>
                <h1>Grid</h1>
            </div>
        );
    }
}

Title.js Title.js

import React from 'React';

const Title = () =>  {
    return (
        <div>
            <h1>Title</h1>
        </div>
    );
}

export default Title;

Now, i try to import both into App.js file it won't. 现在,我尝试将两者都导入到App.js文件中,而不会。

import Title from './Title/Title';
import Grid from './Grid/Grid';

It shows following error. 它显示以下错误。

Failed to compile. 编译失败。

./src/Grid/Grid.js Module not found: D:\\ReactAppCSS\\node_modules\\React\\index.js does not match the corresponding path on disk react . ./src/Grid/Grid.js找不到模块: D:\\ReactAppCSS\\node_modules\\React\\index.js与磁盘上的相应路径react不匹配。

Same for Title.js. Title.js也一样。

Any help would greatly appreciated. 任何帮助将不胜感激。

import React from 'react'

包名是react!

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

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