59

Here is an image of the error and the console error...

Screenshot of Error

My code seems to be correct and the paths of the imports are good too, I don't understand why I'm getting this error.

Notifications.js

import React from 'React'

const Notifications = () => {
    return(
        <div>
            <p>Notifications</p>
        </div>
    )
}

export default Notifications

ProjectList.js

import React from 'React'

const ProjectList = () => {
    return(
        <div>
            <div className="project-list section">
                <div className="card z-depth-0 project-summary">
                    <div className="card-content grey-text darken-3">
                        <span className="card-title">Project Title</span>
                        <p>Posted by Net Ninja</p>
                        <p className="grey-text">3rd September, 2018</p>
                    </div>
                </div>
            </div>
        </div>
    )
}

export default ProjectList
Vega
  • 27,856
  • 27
  • 95
  • 103
josephT
  • 822
  • 1
  • 7
  • 16
  • It seems to work find when I just import Dashboard without its own imported Notifications and ProjectList imports, if that makes sense. – josephT Mar 13 '19 at 19:30
  • 3
    Imports are case-sensitive. In Notifications.js and ProjectList.js you are importing from `'React'` (uppercase "R"). This should be a lowercase "r". – rickdenhaan Mar 13 '19 at 19:30
  • In fact, the error message is "Cannot find 'React' module", which speaks for itself. There is no module React, but react – Vega Jun 11 '21 at 16:45
  • even I'm facing this error. I hate react but have to do as its the next gen. – vibs2006 Nov 23 '22 at 11:55

8 Answers8

150
import React from 'React'

should be

import React from 'react'

You are trying to import React instead of react. The name of module is case-sensitive, in this case the name is react.

2240
  • 1,547
  • 2
  • 12
  • 30
oxfn
  • 6,590
  • 2
  • 26
  • 34
3

You can try this solution from Web-brackets.com
all you need to do is just rename the imported library from React to react with small r like this (on the first line)

import React from 'react';

reference https://web-brackets.com/discussion/6/-solved-cannot-find-file-index-js-does-not-match-the-corresponding-name-on-disk-react-js

Mohamed Atef
  • 115
  • 8
1

Notification.js

import React from 'react'

const Notifications = () => {
return(
    <div>
        <p>Notifications</p>
    </div>
)
}

 export default Notifications

ProjectList.js

 import React from 'react'

 const ProjectList = () => {
 return(
    <div>
        <div className="project-list section">
            <div className="card z-depth-0 project-summary">
                <div className="card-content grey-text darken-3">
                    <span className="card-title">Project Title</span>
                    <p>Posted by Net Ninja</p>
                    <p className="grey-text">3rd September, 2018</p>
                </div>
            </div>
        </div>
    </div>
)
}

export default ProjectList

module name is react not React and since imports are case-sensitive import React from 'React' is causing error

ilia
  • 339
  • 8
  • 23
1

So the issue is because you are not importing correctly. Like in my case it was :

import {Dropdown} from 'react-Bootstrap'

I corrected it to

import {Dropdown} from 'react-bootstrap'

Since import statement are case sensitive

1

I had the same problem and it was because I imported React not react so it should go like this ..

import React from 'react'
Druckles
  • 3,161
  • 2
  • 41
  • 65
Mena Aziz
  • 99
  • 1
  • 2
1

I had the same issue. The thing is that the compilation process uses caches to optimize build time. It's a internal thing to "Babel Loader". To make sure you get a fully refreshed compilation process by webpacker/babel, delete the folder "node_modules/.cache" and run npm start again.

Fernando Vieira
  • 3,177
  • 29
  • 26
0

I think you need to install react-router by using this command - npm install react-router-dom

Follow this link for further details. (https://reacttraining.com/react-router/web/guides/quick-start)

troy
  • 2,145
  • 2
  • 23
  • 31
-2

including when naming your file, in example you import App but the name on your file is app.js this wont allow the system to find the same name.