【问题标题】:index.js:1 Uncaught SyntaxError: Unexpected token <index.js:1 Uncaught SyntaxError: Unexpected token <
【发布时间】:2017-11-24 21:36:52
【问题描述】:

我正在尝试在我们的 IIS 服务器上运行我们的 Web 应用程序的生产版本,它使用 React 的缩小(生产)版本。我们目前可以运行开发版,但是在尝试运行构建版时,我们不断收到以下错误

`index.js:1 Uncaught SyntaxError: Unexpected token <` 

我认为这可能是构建文件夹中的缩小代码,所以我做了一个基本的 index.js,里面只有一个警报,但它仍然失败。我检查了文件路径,它似乎是写的,并且 index.html 文件似乎也是有序的。我们正在使用来自 reactboilerplate.com 的锅炉并运行 npm run build 命令

开发控制台打印输出:

index.html:

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

<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width,initial-scale=1">
 <link rel="manifest" href="manifest.json">
 <meta name="mobile-web-app-capable" content="yes">
 <title>Timeclock</title>
</head>

<body>
 <noscript>If you're seeing this message, that means
  <strong>JavaScript has been disabled on your browser</strong>, please <strong>enable JS</strong> to make this app work.</noscript>
 <div id="app"></div>
 <script type="text/javascript" src="index.js"></script>
</body>

</html>

【问题讨论】:

  • 你在index.js 中使用任何 JSX 吗?有没有试过直接在浏览器中打开index.js查看输出?
  • no jsx,index.js 文件目前只是一个警报功能,只是为了解决问题。浏览器中index.js文件的输出是有效的
  • 尝试打开您的控制台并转到“源”选项卡(假设是 Chrome)。在那里找到index.js,看看浏览器声称里面有什么。这可能就像缓存问题一样简单。
  • 我即将发布我的开发控制台打印输出
  • 您提供的代码与问题无关。

标签: javascript html node.js reactjs


【解决方案1】:

检查您的页面并验证您在获取 index.js 文件时是否确实在获取它。我的猜测是,当您获取 index.js 时,您实际上会获得 index.html,因此当您的浏览器尝试将 index.html 文件的副本作为脚本执行时,它会立即出错,因为 iisconfig.xml 文件中有以下设置:

<configuration>
    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Main Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【讨论】:

  • 那么如何解决这个问题?
  • 请编辑您的答案以包含相关信息,而不是写评论。
【解决方案2】:

设置好 index.js 并与 HTML 文件链接后,您应该删除 index.js 中的内容并直接运行您的代码。错误将消失!就这么简单,但一开始就很棘手。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-04
    • 2016-09-19
    • 1970-01-01
    • 2012-05-17
    • 2019-02-10
    • 2014-07-08
    • 2011-03-09
    • 2014-01-06
    相关资源
    最近更新 更多