javascript - 使用 Javascript 将 React 应用程序嵌入为小部件失败,并在 Firefox 和 Chrome 上显示不同的消息
问题描述
按照本网站上的步骤,我可以使用 iframe 在另一个网站上将反应应用程序作为小部件嵌入:
<html>
<iframe src="http://localhost:3000"><iframe>
</html>
嵌入 Javascript(第二种方法)在 Firefox 上失败并显示以下错误消息:
The script from “http://localhost:3000/static/js/main.dbfc58d6.chunk.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
SyntaxError: expected expression, got '<'
以下是我嵌入反应应用程序的代码:
<html lang="en">
<body><noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="text/javascript" src="http://localhost:3000/static/js/main.dbfc58d6.chunk.js"></script>
</body>
</html>
在 Chrome 上,警告消息显示如下:
index.html:1 A cookie associated with a cross-site resource at http://localhost/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
index.html:10 Cross-Origin Read Blocking (CORB) blocked cross-origin response http://localhost:3000/static/js/main.dbfc58d6.chunk.js with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
寻求指导以解决此问题。感谢您的阅读。
更新:参考@Thai 的回答,我将我的源文件指定为由 react 构建操作生成的文件。如何指定正确的 js 文件来解决我的问题?
解决方案
推荐阅读
- python - 如何处理线程Python中的异常
- database - Ping 失败 - com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链路故障
- html - 在课堂上更改字体系列
- xcode - 为什么 Xcode12 给我 SQLite 编译器错误?
- c++ - 双倍的可靠比较
- spring - 支持 JHipster 微服务基础设施中的社交登录
- r - 在 ggnet 中使用颜色
- dart - 我可以知道 StreamSubscription 何时取消吗?
- linux - 尝试启动 selenium chromedriver unix centos7 时错误 chrome 崩溃
- mysql - 在 kubernetes 上使用 mysql 创建persistanceVolume 时出错