admin管理员组文章数量:1278820
I have a React-router set up which uses parametrized routes:
<Route path="/ments" ments={mentsmentsArray} ponent={NewReactElement} />
<Route path="/ments/:id" ponent={Comment} />
The error: SyntaxError: expected expression, got '<'
I have researched the error, and found out it was happening when the server tries to get a .js/.css/other file, but is returned HTML beginning with <!DOCTYPE>
instead, so I set up the express.static
, but when entering URL such as ments/1250
, it still returns: SyntaxError: expected expression, got '<'
. This is my server setup:
app.use(express.static(__dirname + '/views/webpacked'));
app.listen(5000);
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'views', 'webpacked', 'index.html'));
});
I have also tried:
app.use('/*/*', express.static(...));
But it did not work, either.
Thank you for advice in advance.
I have a React-router set up which uses parametrized routes:
<Route path="/ments" ments={ments.mentsArray} ponent={NewReactElement} />
<Route path="/ments/:id" ponent={Comment} />
The error: SyntaxError: expected expression, got '<'
I have researched the error, and found out it was happening when the server tries to get a .js/.css/other file, but is returned HTML beginning with <!DOCTYPE>
instead, so I set up the express.static
, but when entering URL such as ments/1250
, it still returns: SyntaxError: expected expression, got '<'
. This is my server setup:
app.use(express.static(__dirname + '/views/webpacked'));
app.listen(5000);
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'views', 'webpacked', 'index.html'));
});
I have also tried:
app.use('/*/*', express.static(...));
But it did not work, either.
Thank you for advice in advance.
Share Improve this question asked Apr 1, 2016 at 0:01 user3104270user3104270 6252 gold badges10 silver badges18 bronze badges2 Answers
Reset to default 11I've got a react/react-router page without any express and got the same error:
SyntaxError: expected expression, got '<'
which started to appear as soon as I configured a react route other then just root /
.
After some experimenting I've figured out that in my index.html there was a link to js file:
<script src="bundle.js"></script>
</body>
</html>
So, the solution was to add /
in the source path:
<script src="/bundle.js"></script>
</body>
</html>
and the error has gone.
Hope that could help a bit.
After adding the /
to bundle.js
as this answer suggested the issue still persisted.
I was able to fix the issue by running rm -rf .cache
in my project directory, as per this github issue.
本文标签:
版权声明:本文标题:javascript - React router parametrized routes: SyntaxError: expected expression, got '<' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741220332a2360848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论