The creators of Deno dropped us a very welcome goodie today. I started using Deno about a week ago and instantly fell in love with it. I really wished there was a way to directly reference modules from GitHub without having to register the repo with deno.land/x/ first.
I visited deno.land/x/ today and noticed this:
Today that has been solved. They now allow us to reference any arbitrary github repo or NPM package. Here's how:
To import the amqp
module from GitHub, for example:
// import from master
import { amqp } from "https://deno.land/x/gh:lenkan:amqp/mod.ts";
// import version
import { amqp } from "https://deno.land/x/gh:lenkan:amqp@v0.9.1/mod.ts";
Likewise, to import the numbers
package from NPM just use the following:
// import latest
import { numbers } from "https://deno.land/x/npm:numbers/index.js";
// import version
import { numbers } from "https://deno.land/x/npm:numbers@v0.7.0/index.js";
Top comments (5)
The sample with
numbers
does not work on my side:import { numbers } from "https://deno.land/x/npm:numbers/index.js";
console.log(numbers);
results in
error: Uncaught SyntaxError: The requested module 'https://deno.land/x/npm:numbers/index.js' does not provide an export named 'numbers'
I guess it's about using JS in TS code. Also tried
import * as numbers from "https://deno.land/x/npm:numbers/index.js";
console.log(numbers);
Did you have a simialar issue? Thank you so much!
Oh dear, of course ...
I needed to allow JS in the tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
}
}
Now I got the issue described under github.com/denoland/deno/issues/6082
Good catch. I completely forgot about that setting... LOL. Thanks for posting.
It looks like this feature has been removed (version v1.2.2), am I wrong ?
I would appear you're correct.