【问题标题】:Uncaught SyntaxError: Unexpected token < in chunk.jsUncaught SyntaxError: Unexpected token < in chunk.js
【发布时间】:2021-08-09 20:24:17
【问题描述】:

我需要你的帮助!

我已经部署和构建了应用程序。但是当我重定向到任何页面时,我都会遇到此错误:

Uncaught SyntaxError: Unexpected token

我认为是因为浏览器 await .html 存档和 chunk.js 像这样打开 img

print from error

路线没问题,他找到了路线,但不要打开文件。

在进行一些搜索之前,我发现了 .htaccess 之类的东西,我尝试过但没有用。

我已经在 public/.htaccess 上尝试了这两种 .htacess 模型

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]

</IfModule>
Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]

但它也不起作用。

服务器

const root = require('path').join(__dirname, 'client', 'build')
app.use(express.static(root));
app.get("*", (req, res) => {
    res.sendFile('index.html', { root });
})

我没有任何网络服务器,对不起,但我是学生,我还在学习......

请大家帮忙!

【问题讨论】:

  • 请分享您的 Javascript 代码...
  • 你有一个 Apache Web 服务器的配置和一个 Express Web 服务器的代码。您实际运行的是哪个 Web 服务器?如果两者都有,它们之间的联系是什么?您是否有一些尚未与我们共享的反向代理代码?
  • 您有一个 URL 被视为 JS 并引发错误,因为它在不应该的地方有一个 &lt;。你看过那个文件吗?为什么它不应该在某个地方有一个&lt;?那是一些尚未编译的JSX吗?还是您的“为任何通常会出现 404 错误的 URL 抛出 HTML 文档”代码将 HTML 文档抛出到需要 JS 的浏览器?

标签: javascript node.js reactjs express .htaccess


【解决方案1】:

你将下面这行代码添加到 public 文件夹中的 index.html 中

&lt;base href="your root path"&gt;

或者您可以参考以下链接: https://skryvets.com/blog/2018/09/20/an-elegant-solution-of-deploying-react-app-into-a-subdirectory/

【讨论】:

    猜你喜欢
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    相关资源
    最近更新 更多