当我通过webpack包含jquery.flot.resize.js时,会生成“未捕获的TypeError:e.setTimeout不是函数”。
这是我的代码。
<?xml version="1.
0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Teacher_searching"
android:orientation="vertical">
<ListView
android:id="@+id/lview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
这会在浏览器控制台中造成类型错误。
import "jquery.flot/jquery.flot.js";
import "jquery.flot/jquery.flot.resize.js";
如果它使用标记加载相同的javascript,则效果很好。 该错误仅在webpack上发生。
答案 0 :(得分:0)
就我而言,以下语法解决了该问题:
import * as [some-name] from '[reference to your file or directory]';
答案 1 :(得分:0)
该错误是由“ jquery.flot.resize.js”中的一个假设引起的,该假设是this
包含window
,在使用webpack编译时不成立。有问题的代码不是源代码本身,而是复制粘贴的依赖项(jQuery调整大小事件)。
The problem seems to have been solved in October 2019,当他们粘贴了其他版本的依赖项时。此更改已在flot 4.2.0中发布。
如果您需要使用早期版本的flot,则可以使用webpack imports-loader解决该问题,例如(已将imports-loader添加到应用程序(dev)依赖项中):
// ./webpack.config.js
module.exports = {
...
module: {
rules: [
{
test: require.resolve("jquery.flot/jquery.flot.resize.js"),
use: "imports-loader?this=>window"
}
]
}
};