6

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
  • It might not help but have you tried to run npm install to make sure everything is installed properly? Commented Mar 20, 2021 at 23:24
  • I tried this but the error comes up straightaway.
    – James Gee
    Commented Mar 20, 2021 at 23:25
  • Have you solved this?
    – Ajeet Shah
    Commented Mar 25, 2021 at 7:21

4 Answers 4

13

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 )

1
  • Yes I have tried changing it around a few times and still the same problem.
    – James Gee
    Commented Mar 20, 2021 at 23:27
4

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

1

1.diveLogTable.component.js instead, you should do DiveLogTable.Component.js OR DiveLogTable.js.

2.Ensure you have imported React in all the files that have jsx. Like, import React from 'react' It might also be required by your build system that files with jsx have .jsx or .tsx extensions (not just .js / .ts).

3.Ensure that file names that are referenced in your code are matching actual file names in a filesystem. There could be issues if file names had changes in capitalization. Keeping file names in lowercase might be a good idea to avoid such sort of problems.

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.