Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

misleading webpack.config snippet code #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wayann
Copy link

@wayann wayann commented Nov 17, 2016

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

if you follow the lesson and copy the path param in the webpack config snippet code 
// webpack.config.js
  output: {
    path: 'public',
    ....
  }

that will install bundle.js in the public dir but index.html is not yet there, so when you run the browser, it will replace bundle.js with index.html
and it will output a weird error:
SyntaxError: Unexpected token '<'
for a noob like me took me a while to figure it out...
@Andersos
Copy link

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

@cormickjbrowne
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants