i.brod
i.brod

Reputation: 4603

Is there a convenient way to import NPM modules into Deno, which have their own dependencies?

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

Answers (1)

Marcos Casagrande
Marcos Casagrande

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

Related Questions