Reputation: 4603
I've come across this post, that explains how to use (some)NPM modules in Deno: How to use npm module in DENO?
Problem is, the example libraries they give have 0 dependencies.
But what happens, if i want to use a dependency like Axios(might be a bad example because it might not even work with the Node compatibility layer, but it's just an example), which has its own dependencies?
Is there any way to do this, besides manually copying those libraries to my code?
Upvotes: 1
Views: 1168
Reputation: 40414
Problem is, the example libraries they give have 0 dependencies.
It works the same way for packages with multiple dependencies.
import { createRequire } from "https://deno.land/std/node/module.ts";
const require = createRequire(import.meta.url);
const isEven = require("is-even");
console.log(isEven(2))
As long as the dependencies don't use non-polyfilled Node.js APIs it will work just fine.
You can also use https://jspm.io/
which will convert NPM modules to ES Modules
All modules on npm are converted into ES modules handling full CommonJS compatibility including strict mode conversions.
import isEven from 'https://dev.jspm.io/is-even';
console.log(isEven(2))
Upvotes: 1