react-router-tutorial
react-router-tutorial copied to clipboard
misleading webpack.config snippet code
if you follow the lesson and copy the path param in the webpack config snippet code
// webpack.config.js
output: {
path: 'public',
filename: 'bundle.js',
publicPath: '/'
}
that will install bundle.js in the public dir but index.html isn't there yet and the script src tag of index.html is pointing to root of the dir.
which will lead to output a weird error:
SyntaxError: Unexpected token '<'
because the browser somehow will replace bundle.js with index.html...
for a noob like me took me a while to figure it out...
Where are you getting SyntaxError: Unexpected token '<'
?
This happened to me too. @Andersos you see the SyntaxError: Unexpected token '<'
in the browser console. The browser makes a request to /bundle.js but doesn't find the bundle because webpack has put the file at /public/bundle.js. The request continues and when it gets to this section
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
express serves index.html
again. The browser reads the file and barfs when it tries to interpret the html as javascript.