【问题标题】:Refused to execute script from 'bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled拒绝执行来自 'bundle.js' 的脚本,因为它的 MIME 类型 ('text/html') 不可执行,并且启用了严格的 MIME 类型检查
【发布时间】:2021-06-15 12:34:38
【问题描述】:

我有一个带有前端和 django 后端的 CRA 应用程序。我使用react-app-rewired 覆盖前端的 webpack 配置,以便保存 webpack-dev-server 的输出供 django 使用。

但我遇到了如下截图所示的问题。

下面是我的 override-config.js,它用于覆盖开箱即用的 CRA webpack 配置

奇怪的事情是前端产品构建没有这样的问题(运行yarn build然后在浏览器中打开localhost:8000,我可以正确获取前端)。以上Refuse to execute ... 问题仅在我在开发模式下运行yarn start 时发生。

这是我的 package.json

还有 django frontend.html

django settings.py 中的相关部分

提前感谢您的帮助!!!

【问题讨论】:

    标签: reactjs django webpack webpack-dev-server django-webpack-loader


    【解决方案1】:

    这是否仅在调试模式下发生,即 Django settings.py 中的 DEBUG = True?也许你会尝试将assets 添加到 urlpatterns

    urls.py

    if settings.DEBUG:
        urlpatterns += static("/assets/",
                              document_root=settings.FRONTEND_PRODUCTION_DIR) 
    

    在此处引用document

    【讨论】:

    • 谢谢。对于前端生产和开发模式,Django DEBUG 始终为 True。添加 urlpatterns 不能解决这个问题。
    猜你喜欢
    • 2018-09-30
    • 2018-09-20
    • 2017-10-02
    • 2018-04-17
    • 2015-07-25
    • 2022-08-21
    • 2020-06-30
    • 2018-08-20
    • 2020-04-23
    相关资源
    最近更新 更多