React/Node Uncaught SyntaxError:意外令牌< [英] React/Node Uncaught SyntaxError: Unexpected token <

查看:109
本文介绍了React/Node Uncaught SyntaxError:意外令牌<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一切,但是对于应该在哪里研究这个问题,我有些迷茫.

I've tried everything but I'm a bit lost on where I should look into this issue.

发生的事情是,一旦构建了React应用并部署它(使用node/express),它就会完美运行.但是,如果再次构建并将构建文件夹带到节点服务器,则会给我该语法错误.仅在您的浏览器已经打开过一次应用程序的情况下才会发生这种情况.

What happens is that once you build the react app and deploy it (using node/express), it works perfectly. However, if you build again and take the build folder to the node server, it gives me that syntax error. This only happens if your browser already opened the app once.

我已经进行了研究,人们说浏览器正在尝试加载较旧的静态文件,这就是这种情况发生的原因.尽管根据我的尝试,他们的解决方案都没有效果.

I've done research and people were saying that the browser is trying to load the older static files and that's why this occurs. None of their solutions worked though from what I've tried.

非常感谢任何人在此问题上的帮助.

I would very much appreciate anyone's help with this issue.

欢呼

更新

如达文(Davin)所建议.我调查了chrome devtools,这就是我在响应中得到的结果

As Davin suggested. I looked into the chrome devtools and here is what I got back in the response

<!DOCTYPE html>
<html lang="en" id="html">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <script src="/js/modernizr.js"></script>
    <link rel="manifest" href="/manifest.json">
    <link rel="shortcut icon" href="/favicon.ico">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
        integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
        crossorigin="anonymous"></script>
    <link rel="stylesheet" href="/css/mega-nav.css">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.1/css/swiper.min.css">
    <title>Q Parts</title>
    <link href="/static/css/style.css" rel="stylesheet">
    <link href="/static/css/main.css" rel="stylesheet">
    <link href="/static/css/main-ar.css" rel="stylesheet">
</head>

<body><noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="https://code.jquery.com/jquery-migrate-3.0.1.min.js"></script>
    <script src="/js/jquery.mobile.custom.min.js"></script>
    <script src="/js/popper.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/main.js"></script>
    <script>$(document).ready(function () { $(".has-children").hover(function () { $(".overlay-lg").addClass("is-visible") }, function () { $(".overlay-lg").removeClass("is-visible") }), $(".cd-primary-nav li").click(function () { $(".cd-primary-nav").animate({ scrollTop: $(".nav-is-visible").offset().top }, "200") }) })</script>
    <script type="text/javascript" src="/static/js/main.957b5c6e.js"></script>
</body>

</html>

推荐答案

谢谢大家,帮助我解决了这个问题.我接受了@Davin的建议,并打开了开发工具(chrome).我用谷歌搜索了同样的问题,但添加了_sw-precache.最终,我发现人们面临着同样的问题,所以这是他们的建议:

Thank you everyone, for helping me out with this issue. I took @Davin's suggestion and opened the dev tools (in chrome). I googled the same issue but added _sw-precache. Eventually, I found people were facing the same issue so here is what they suggested:

只需将<base href="/" />添加到我的index.html中即可为我修复.

Just add <base href="/" /> into the of my index.html fixed it for me.

https://github.com/webpack/webpack/issues/2882 #issuecomment-280906981

这篇关于React/Node Uncaught SyntaxError:意外令牌&lt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆