首页 > 解决方案 > "Uncaught TypeError: undefined is not a function" vanishes after computer restarted

问题描述

I'm building a React component library using rollup for the build and webpack-dev-server to run a demo. While hacking away last night, using the demo to see my changes, I was running into an Uncaught TypeError: undefined is not a function that would simply not go away as long as a certain line was included in my code.

The line of code was defaultCheckboxRender(CheckboxComponent, label); but please just assume that sufficient debugging was done to determine that none of those identifiers were undefined and that all were within the proper scope. After slamming my head on this for several hours, I shut down my Windows 10 computer to install some updates and went to bed. This morning, I boot up my project, run the demo to continue this nightmare and, lo and behold, the error is gone. I did not change the code since I last encountered the error but for some reason, it's not happening anymore.

Now... I set up the webpack config myself and it was the first time I have done such a thing. My best guess is that this problem is related to how the files are served and compiled and such. Here is the webpack.config.js file https://gist.github.com/dumptruckman/db7001568077497fe1aaa0b4db9d8424. One thing to note is that when I run my demo, I do not see a dist folder appear in my project directory which struck me as kind of odd but I'm not sure why it's like that.

Has anyone experienced anything like this before and how do I prevent it from happening in the future?

标签: javascriptreactjswebpackwebpack-dev-server

解决方案


通过将 HotModuleReplacementPlugin 添加到我的 webpack 配置中解决了这个问题。更新的配置可以在这里看到:https ://gist.github.com/dumptruckman/7de7ff7e9526bff4408f0cea6fb4bbe5


推荐阅读