***Update for 2018: For anyone else running into errors that Webpack was complaining about the jsx syntax with Unexpected token(note: keep index.js with the .js ending, that’s )

Anyway, everything else equal, you change webpack.config.js to

var path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'index.js',
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.js?$/,
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['react']
}
}
]
}
]
},
externals: {
'react': 'commonjs react'
}
};

and also I needed to install babel-preset-react:

npm install — save-dev babel-preset-react

Then it works!

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store