Home > Blockchain >  npm start for react project gives error "Cannot find file: index.js"
npm start for react project gives error "Cannot find file: index.js"

Time:01-07

I have been building a project on react using vscode and when i try to start it in the browser, I keep getting the error that it cant find the file index.js, even though it is in the right folder. (Yes I have imported react and not React). I have literally paused my project for a while day because of this and its weird because i was building a smaller project earlier on the same mahine, in the same way and it worked perfectly. But I have no idea whats going on here, I have attached the code.

I tried moving the file around, checking my lowercase, deleteing the cache memory and restarting it, deleting the node modules folder and using npm insall, etc all that stuff already on stackOverflow but nothing works. I am just starting out with react so I'm not sure what the problem is and I've tried googling as much as I could

Navbar.js:

import React from 'react'
import logo from './images/airbnb 1.png'

export default function Navbar(){
    return (
        <img src={logo} width= "40px"></img>


    )
}

App.js:

import React from 'react'

export default function App(){
    return(
        <h1>App component</h1>
    )
}

index.js:

import React from 'react'
import ReactDOM from 'react-DOM'
import App from './App'
import './index.css'

ReactDOM.render(<App />, document.getElementById("root"))

CodePudding user response:

You may want to check the file in your package.json to point exactly to your index.js path. Or maybe your npm start script doesn't correctly configure. Do you use Git? If you use Git, maybe it was accidentally changed. By using Git, you can revert to the previous commit. Try checking this reference here

Hope this helps!

CodePudding user response:

import ReactDOM from 'react-dom'
  • Related