首页 > 解决方案 > 拒绝从 packs/js/index-662807e73049021453fe.js' 执行脚本,因为它的 MIME 类型('text/html')

问题描述

我使用 react/rails 部署了一个带有 aws ec2 实例的网站。通过 rails s -e production 运行服务器时,出现此错误

Refused to execute script from 'http://<ip-address>/packs/js/index-662807e73049021453fe.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

我的 application.erb.html


<!DOCTYPE html>
<html>
  <head>
    <title>Production server</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'index' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>

我一直在寻找一个星期的答案。任何帮助将不胜感激。

更新:

我的路线以捕获 routes.rb 中的所有路线

 root 'homepage#index'
  get ':path', to: 'homepage#index', format: false

这指向主页视图

 <%= javascript_pack_tag 'index' %>
 <%= react_component("App", {prerender: true}) %>

标签: mime-typesruby-on-rails-6script-tag

解决方案


推荐阅读