Skip to content

Node compatibility #2644

Closed
Closed
@ry

Description

@ry

We've resisted considering Node compatibility as Deno was under initial development so that those considerations didn't influence the design. But now Deno has a relatively established API and the URL module system is deeply baked in. It is unlikely, at this point, that considering compatibility with existing Node modules will compromise Deno's design goals.

It's unlikely we can make Node code work 100% of the time. But we can do a lot to make porting modules over easier. Let's discuss how make Deno work with existing Node code. Here are some ideas:

  • One direction could be a transpilation program that takes a CommonJS node file, and translates it into ES modules.

  • Node has core APIs like file system and networking which are different (sometimes subtly so) in Deno. For example, require('fs').readFileSync() in Node supports encoding to strings, Deno.readFileSync() does not. I suggest we implement a compatibility layer in deno_std/node to match the semantics. (There has been some effort to do this already in https://github.com/denolib/node, but progress is slow, I think it makes sense to do it in deno_std.)

  • We should attempt a require() implementation. It should probably be in deno_std rather than deno itself. It might make sense to base this on top of dynamic import Support dynamic import #1789 (which will land very soon - see Dynamic import #2516).

Existing work

Metadata

Metadata

Assignees

No one assigned

    Labels

    suggestionsuggestions for new features (yet to be agreed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions