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

Time:04-20

I was using react-vis library. Their readme file says following:

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.

When I do exactly that, it works and I was able to use reactVis object in my code. It links versions 1.11.7 from unpkg. I wanted to try out version 1.11.5. So, I tried following:

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/style.css">
<script type="text/javascript" src="https://unpkg.com/browse/[email protected]/dist/dist.min.js"></script>

But, now it gives me following error:

Uncaught ReferenceError: reactVis is not defined

Somehow, it is not able to get reference to reactVis code. Why is this so?

CodePudding user response:

The link you used contains https://unpkg.com/browse/... /browse links to the html preview page of the file.

To link to the raw version of the file remove /browse in your case to https://unpkg.com/[email protected]/dist/dist.min.js, which would link to the file raw.

eg.

console.log(
  reactVis
)
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/style.css">
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/dist.min.js"></script>

  • Related