Does npm unit-converts package work with https://unpkg.com

135 views Asked by At

I'm facing problems importing npm package 'convert-units' with unpkg, I tried this :

<script src="unpkg.com/[email protected]/lib/index.js"></script>

But it seems not to work

1

There are 1 answers

3
Felipe Candal Campos On

I came with an idea, I can't see the whole code, but... Are you requesting this package BEFORE any other JavaScript that uses this function?

I mean, something like this:

<script src="unpkg.com/[email protected]/lib/index.js"></script>
<script src="...ROUTE_TO_JAVASCRIPT"></script>

Otherwise, if you first use package functions and then import it, those functions would be not defined.

So, remember, order matters in this scenario.

If you did this, you need to import the module in every place that you use it:

var convert = require('convert-units')