react-router-tutorial icon indicating copy to clipboard operation
react-router-tutorial copied to clipboard

misleading webpack.config snippet code

Open wayann opened this issue 8 years ago • 2 comments

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...

wayann avatar Nov 17 '16 22:11 wayann

Where are you getting SyntaxError: Unexpected token '<' ?

Andersos avatar Nov 23 '16 10:11 Andersos

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.

cormickjbrowne avatar Dec 17 '16 23:12 cormickjbrowne