2

I understand that most of npm packages are not compatible with Deno.js due to using require(), at least the ones not in deno.land/x.

But is the opposite possible? Can a Deno.js script be used in a Node.js project?

If yes, then how to convert the URL script into a node_modules package?

Ahmed Hammad
  • 2,798
  • 4
  • 18
  • 35
  • No, a Deno.js script cannot generally be executed by Node.js – Paul May 16 '20 at 04:22
  • Would the negative voters provide comments, please? – Ahmed Hammad May 16 '20 at 04:37
  • 1
    A deno script that was written in Javascript could run in node.js if it was either plain Javascript (with no dependencies) or had dependencies that were also compatible with node.js. A deno script that was TypeScript would have to first be compiled to Javascript and then could run in node.js if it met the same previous conditions. Code that uses features in the Deno standard library that are not the same as what is in node.js would not run in node.js. – jfriend00 May 16 '20 at 04:59

1 Answers1

2

The opposite would have similar constraints.

The only practical way that a script can run on both Deno and Node.js, without pain and without adapting the code, is that if uses plain JavaScript.

Suppose you want to build a portable app to run on both Node.js and Deno:

  • In short, standard libraries are not portable, so you'll have to rely on portable external libraries, or modularizing your app so that you can plug in the components. Imagine dealing with that.
  • 3rd-party libraries must also be portable. A lot of Deno libraries, if not most, are written in TypeScript.
  • For practical reasons you'll have to choose JavaScript over TypeScript. Why impose such restriction if one wants to use TypeScript and get benefits of it? Also the Deno community is very strong with TypeScript.

A system in the real world cannot scale with these restrictions.

Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165