Getting JS error after changing versions: Uncaught ReferenceError: Xyz is not defined

Getting JS error after changing versions: Uncaught ReferenceError: Xyz is not defined

我正在使用 react-vis 库。他们的自述文件内容如下:

If you're working in a non-node environment, you can also directly include the bundle and compiled style using basic html tags.

<link rel="stylesheet" href="https://unpkg.com/react-vis/dist/style.css">
<script type="text/javascript" src="https://unpkg.com/react-vis/dist/dist.min.js"></script>

The global reactVis object will now be available for you to play around.

当我完全这样做时,它起作用了,我能够在我的代码中使用 reactVis 对象。它链接版本 1.11.7 from unpkg。我想试用版本 1.11.5。所以,我尝试了以下操作:

<link rel="stylesheet" href="https://unpkg.com/react-vis@1.11.5/dist/style.css">
<script type="text/javascript" src="https://unpkg.com/browse/react-vis@1.11.5/dist/dist.min.js"></script>

但是,现在它给了我以下错误:

Uncaught ReferenceError: reactVis is not defined

不知何故,它无法获得对 reactVis 代码的引用。为什么会这样?

您使用的 link 包含 https://unpkg.com/browse/... /browse link 文件的 html 预览页面。

要 link 到文件的原始版本删除 /browse 在你的情况下到 https://unpkg.com/react-vis@1.11.5/dist/dist.min.js,这将 link 到原始文件。

例如

console.log(
  reactVis
)
<link rel="stylesheet" href="https://unpkg.com/react-vis@1.11.5/dist/style.css">
<script type="text/javascript" src="https://unpkg.com/react-vis@1.11.5/dist/dist.min.js"></script>