Cannot find file: 'index.js' does not match the corresponding name on disk: '.\node_modules\React\react' error with React import correct

Viewed 8133

I am getting the below error on a page that is stopping it being rendered and after checking other similar errors I have double checked the import is correct and the node_modules react index file is installed.

What else could be causing this? I have had linting issues yesterday out of nowhere that I thought had fixed themselves.

The file this refers to should be node_modules/React/react.indexjs but on my system is node_modules/react.index.js. I haven't changed this myself so i'm not sure where it has come from. I have also removed any code that was added to this file which could of been causing it.

Cannot find file: 'index.js' does not match the corresponding name on disk: '.\node_modules\React\react'

enter image description here

enter image description here

3 Answers

This happens when you import react like this

import React from "React"

notice the capital R

instead, you should do :

import React from "react"

( with a small r )

This happens due to case sensitivity. Check if the file name is exactly the same in the same case.

Eg:

Cannot find file: 'CheckBox.js'

Check if the filename is exactly CheckBox.js not Checkbox.js

try creating the index.js in the src folder, i'm sure you created it outside the src folder.

Related