【问题标题】:Hot module replacement does not work with some modules热模块更换不适用于某些模块
【发布时间】:2017-06-22 00:07:27
【问题描述】:

我遇到了 react hot loader 3 的问题。

我的应用程序中的一些模块得到了热更新,而另一些则没有。我有一个文件夹(应用程序),其中包含我所有的组件。在这个文件夹中,我有 index.js,我从文件夹中导出所有模块。在文件夹中,我有 index.js 导出组件本身的文件。 示例:

app/test 包含 test.jsindex.js app/test/index.js 包含 export test from ./test.js app/index.js 包含 export * as test from ./test

在我的应用程序的某个地方,我像这样导入这个测试应用程序import { test } from ../app

这里是魔法出现的地方。 hmr 不适用于 test.js。但是如果我在app/index.js 中评论export * as test from ./test 行并且我直接导入我的测试组件import test from ../app/test/test.js hmr 工作。我已经尝试修复它3天了。 app/index.js 被导入到我的 routes.js 文件中。这是唯一一个进口的地方。只有app 文件夹中的所有组件都不会得到热更新,除非它工作正常。我试图用任何样板复制它,但没有成功。

在控制台中我看到了

[WDS] App updated. Recompiling...
log-apply-result.js?d762:11 [HMR] The following modules couldn't be hot updated: (They would     need a full reload!)
log-apply-result.js?d762:18 [HMR] Nothing hot updated.
only-dev-server.js?2f87:49 [HMR] App is up to date.
client?e36c:37 [WDS] App updated. Recompiling...
client?e36c:37 [WDS] Nothing changed.

【问题讨论】:

    标签: reactjs webpack react-hot-loader hot-module-replacement


    【解决方案1】:

    问题在于文件夹的结构。循环依赖失败 hmr。修复它修复了问题。

    【讨论】:

    • 是的,这也修复了我的代码,愚蠢的错误。始终检查您的代码是否存在循环依赖项
    猜你喜欢
    • 1970-01-01
    • 2020-02-29
    • 2017-07-06
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2017-06-28
    • 2018-02-06
    • 2020-11-23
    相关资源
    最近更新 更多