Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

misleading webpack.config snippet code #261

Open
wayann wants to merge 1 commit into reactjs:master
base: master
Choose a base branch
Loading
from wayann:patch-1

Conversation

@wayann
Copy link

@wayann wayann commented Nov 17, 2016
edited
Loading

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

fr33kvanderwand and cormickjbrowne reacted with thumbs up emoji
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...
Copy link

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

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.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /