How to import NPM package in JSFiddle?

josemigallas picture josemigallas · Oct 20, 2017 · Viewed 9.7k times · Source

I would like to use valid-url to validate some URLs using JSFiddle so that I can share it later. I tried adding a link to the index.js file from Github (https://raw.githubusercontent.com/ogt/valid-url/master/index.js) but Fiddle says:

Github is not a CDN, using it as such will cause issues with loading the file. Do you still with to it?

And obviously when I try to use it, an error is thrown:

Refused to execute script from [...] because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

So, is there any way to use npm packages in a JSFiddle? Or any workaround to achieve this?

Answer

Lance Pollard picture Lance Pollard · Jan 18, 2018

Use unpkg.com. They allow you to load any npm module from the browser like a CDN.