热模块更换不适用于某些模块
Hot module replacement does not work with some modules
我在使用 React 热加载程序 3 时遇到问题。
我的应用程序中的一些模块得到了热更新,有些则没有。我有一个包含我所有组件的文件夹(应用程序)。在这个文件夹中,我有 index.js,我从文件夹中导出所有模块。在文件夹中,我有 index.js
导出组件本身的文件。
示例:
app/test
包含 test.js
和 index.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.
问题出在文件夹的结构上。循环依赖失败了 hmr。修复它解决了问题。
我在使用 React 热加载程序 3 时遇到问题。
我的应用程序中的一些模块得到了热更新,有些则没有。我有一个包含我所有组件的文件夹(应用程序)。在这个文件夹中,我有 index.js,我从文件夹中导出所有模块。在文件夹中,我有 index.js
导出组件本身的文件。
示例:
app/test
包含 test.js
和 index.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.
问题出在文件夹的结构上。循环依赖失败了 hmr。修复它解决了问题。