Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with router. It uses relative paths. Getting error: expected expression, got '<' #77

Open
pejrich opened this issue Dec 15, 2019 · 1 comment

Comments

@pejrich
Copy link

pejrich commented Dec 15, 2019

My routes work fine unless they are nested more than one level deep.

If I have this:

<Switch>
    <Route path="/rooms/:id" component={ShowRoom} />
    ...
</Switch>

I get errors on that page:

The script from “http://localhost:3000/rooms/b26a5036f70d782b55c3.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
d1e1eb23-80b3-4b62-af38-1baa520c1b3c
The script from “http://localhost:3000/rooms/vendor.b26a5036f70d782b55c3.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
d1e1eb23-80b3-4b62-af38-1baa520c1b3c
The script from “http://localhost:3000/rooms/app.b26a5036f70d782b55c3.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
d1e1eb23-80b3-4b62-af38-1baa520c1b3c
SyntaxError: expected expression, got '<'
b26a5036f70d782b55c3.js:1
SyntaxError: expected expression, got '<'
vendor.b26a5036f70d782b55c3.js:1
SyntaxError: expected expression, got '<'

It looks like somewhere it's injecting the .js file as a relative path <... src="app.xxxxx.js">, instead of <... src="/app.xxxxxx.js">

I can't find where it is. Any help?

@nmedvedev1
Copy link

nmedvedev1 commented Dec 17, 2019

You can fix it with publicPath: '/' in webpack.config.js output
Maybe like this:
output: { publicPath: isProduction ? './' : '/', path: outPath, filename: isProduction ? '[contenthash].js' : '[hash].js', chunkFilename: isProduction ? '[name].[contenthash].js' : '[name].[hash].js' }

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

No branches or pull requests

2 participants