Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Router 4 Basics Getting Started with React Router Installing React Router and Declaring Routes

Module not found: Can't resolve 'react-router-dom'

my page wont load correctly keep getting this error

Module not found: Can't resolve 'react-router-dom'

i checked the package.json file and react-dom is there under dependencies

not sure whats going on

Add the json and the code where you are importing it for us to see?

{
  "name": "course-directory",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "1.0.6"
  },
  "dependencies": {
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-router-dom": "^4.3.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
import React from 'react';
import {
  BrowserRouter,
    Route,
    Switch
} from 'react-router-dom';

Try deleting and reinstalling your node modules rm -rf node_modules and then reinstalling, either npm install or yarn install if you're using yarn.

1 Answer

thanks Brendan Whiting installed react-router-dom separately using npm i react-router-dom command

Thanks, Brendan and Olu. I ran into the same problem and using "rm -rf node_modules" and then "npm i react-router-dom" fixed it for me.