Import package without npm

Iron Contributor

I'm sure that there's a simple answer to this, but how do I import a JavaScript package that does not exist in npm?  I've found one I'd like to try out but there's no npm listing for it.  Just typing an import statement and providing the path (I tried both relative and full) doesn't seem to do the trick.  Thanks.

2 Replies

It depends. On where you deploy..

you could refer to a js somewhere on the internet that is just like referencing in a normal page.

I have made an executive decision and decided to close this issue.

 

I did some poking around, experimenting with different approaches, and tried a couple of different things.  My bigger problem actually turns out to be friction between Typescript the way the code is written in the .JS files I am trying to use.  It turns out that the .JS is *very* JavaScript, and the Typescript transpiler doesn't like it AT ALL.

 

Since "all JavaScript is actually Typescript" I tried importing the files directly in my project and referencing them in the HTML in my SPFx web part.  That didn't work.  Then I got the wild idea to just change the file extension to .TS and to import them directly from the project folder.  THAT was interesting because although it did not work, I got a better idea of WHY it did not work.  There were several hundred errors reported when I did the gulp serve. My take away was that it would require a conversion from the old .JS to a "real" .TS file, and I just don't have time for that.

 

The result of all this is a decision on my part to avoid trying to make this library work with the SPFx at this time.  The library is still usable with the old Content Editor Web Part trick (although that requires that the tenant have scripting enabled on the site where I will be using it).  I will just have to wait to see if the author decides to port his product to Typescript to work with the SPFx.

 

Thanks for your help.