This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

React Router: Development Environment Setup

4:43 React lesson by

In this lesson we'll install our dependencies and setup a simple build process for converting our ES6 into ES5 using Babel and Webpack for the rest of the react-router lessons.

Get the Code Now
click to level up comment guidelines


In this lesson we'll install our dependencies and setup a simple build process for converting our ES6 into ES5 using Babel and Webpack for the rest of the react-router lessons.


Hi Joe,

Thanks for doing this! It's a great tutorial, nice and clear.

Any chance you could show how to do route testing?



Hi Joe, I see that you have autocomplete with file suggestions when importing, which sublime extension enables that?


It might be better to just put babel configs in the package.json file like

"babel": {
    "presets": [

I'm still learning npm, webpack, etc. so I'm probably missing something obvious, however I'm having a hard time reconciling the videos (Dev Env Setup and Router, Route & Link) with the source code on github. The video setup doesn't mention any css files for formatting though the tutorial seems to be referencing shared.css. The index.html file in Router, Route & Link references these scripts, but I don't see where the tutorial explains them:

<script src="/build/shared.js"></script>
    <script src="/build/router-route-link.js"></script>

I tried cloning straight from github (then npm install and npm start per and notice the server.js file also references the /build/ directory and maybe some sort of routing for the various lessons -- but again, the lesson videos don't seem to provide any direction on how to interface with the code that isn't directly covered in the lesson (at least the first two videos).

I was able to setup dev env and get Router, Route & Links working (sans formatting) -- but am I missing some documentation or basic setup instructions to better interface the github source code in support of the lessons? Thanks for your help.


Webpack in the repo is set up a bit differently than the lessons in order to account for navigating to multiple lessons as root routes.

Something like:

<script src="/build/shared.js"></script>
<script src="/build/router-route-link.js"></script>

Is the equivalent of the single bundle.js from the lessons.

The only css used in the repo is as follows:

nav a {
  display: block;

This simply lays out the anchor tags in block mode, but does not impact the functionality of any lesson in this series.

In reply to

I've taken to using the .babelrc file for babel configuration, but to each his own. This could also be done in the webpack.config.js using:

module: {
    loaders: [
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          presets: ['es2015', 'react']
In reply to Yujing

which editor tools are teacher used


hi Joe, what;s the package name for that webpack config starter in package control? can't seem to find it by search webpack

Ezio Auditore da Firenze

I'm getting this error:

Module build failed: Error: Final loader didn't return a Buffer or String
    at DependenciesBlock.onModuleBuild (D:\Studies\react-router\node_modules\webpack-core\lib\NormalModuleMixin.js:299:42)
    at nextLoader (D:\Studies\react-router\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
    at DependenciesBlock.onLoadPitchDone (D:\Studies\react-router\node_modules\webpack-core\lib\NormalModuleMixin.js:262:4)
    at DependenciesBlock.loadPitch (D:\Studies\react-router\node_modules\webpack-core\lib\NormalModuleMixin.js:182:27)
    at DependenciesBlock.doBuild (D:\Studies\react-router\node_modules\webpack-core\lib\NormalModuleMixin.js:241:4)
    at (D:\Studies\react-router\node_modules\webpack\lib\NormalModule.js:84:14)
    at Compilation.buildModule (D:\Studies\react-router\node_modules\webpack\lib\Compilation.js:126:9)
    at D:\Studies\react-router\node_modules\webpack\lib\Compilation.js:309:10
    at D:\Studies\react-router\node_modules\webpack\lib\NormalModuleFactory.js:58:13
    at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\Studies\react-router\node_modules\tapable\lib\Tapable.js:75:69)
 @ multi main
In reply to Jin

Hi Joe,

Thanks for the tutorial. In the tutorial, you have used react-router 2.0.0, but when I am installing it in my local, the latest version is 3.0.0. Is there any major difference in between these two versions?

Also, I would recommend to update tutorial with latest modules, if major updates are there, add new feature specific tutorials in the list.

Hey, guys. In this video, we are going to set up our development environment for working with React Router. We're going to go ahead and npm-init to create our package json. We'll just enter through all this, clear this out. We're going to install React, ReactDOM, and React Router. We'll go ahead and save those.

For our build process, we're going to go ahead and install Webpack, webpack-dev-server, babel-core, babel-loader, and then we're going to have a couple presets -- preset-es2015 and babel-preset-react. We're going to save those to our dev dependencies. Cool.

Now that those are installed, we're going to go ahead and touch a .babelrc file and a webpack.config.js file. We're also going to make a directory here called source, and inside of that, we're going to touch index.html, app.js, and main.js. Most of our work will be in app.js, and main.js will just consume app.js. We'll go ahead and create those and jump over here to our project.

In app.js, we're going to create a React component. We're going to import React from React, and we're going to go ahead and create a stateless function here. We'll return an h1 that says "hello world." Then we'll go ahead and export that by default.

Then over here in our main.js, we're going to import React, we're going to import ReactDOM, and, of course, we're going to import our app component from app. We're going to ReactDOM render our app component to document.getElementByID. We're going to call that "app."

Here, in our index, we're going to create a quick HTML, say React Router, and we're going to create our app div or target for our main component. Then we're going to have a script, and its source is going to be bundle.js, and that's going to be the compiled JavaScript that we're going to create from Webpack.

We're going to jump over to our babelrc, and we're going to create a very simple object here with a key of presets, which is going to be an array. In there, we're just going to have each of our presets, so es2015 and React.

We'll save that and we'll go ahead and set up our Webpack config. I've got a snippet for this as to not bore you, but our entry point is going to be our source/main.js. For our output, our path is going to be source. We're going to run everything out of there. Then our final name is going to be bundle.js, which is expected by our index HTML.

Our content base for our dev server, this is basically where we want to run everything out of, so we're going to run everything out of that source directory. Then here in our loaders, we're going to set up our test for Babel. That's simply going to be .js at the end of any file. We're going to exclude node modules, and our loader will be Babel. That will pick up on the babelrc file that we created earlier.

The last thing we're going to do is create a start script in our package json. We're just going to say webpack-dev-server. One thing to note here is we are going to be working with React Router 2.0. There are some differences between 1.0 and 2.0. I'll try to point those out along the way.

Now we should be able to go ahead and just run npm-start. It says we're at local host 3333. There's our "Hello world," and if we jump back over here to our app and say, "hi world," that guy will refresh. Cool. We are ready to start working with React Router.

Joel's Head
Why are we asking?