Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there any guideline to use npm modules within deno? #2904

Closed
yrong opened this issue Sep 10, 2019 · 7 comments
Closed

is there any guideline to use npm modules within deno? #2904

yrong opened this issue Sep 10, 2019 · 7 comments

Comments

@yrong
Copy link

yrong commented Sep 10, 2019

No description provided.

@bartlomieju
Copy link
Member

Most of npm modules can't be used directly with Deno.

Deno requires ES modules and imports with extensions. There is an issue for Node compatibility #2644 for tracking this

@ry
Copy link
Member

ry commented Sep 10, 2019

@yrong Look at this repo by @nzakas https://github.com/humanwhocodes/env as an example of how to make a module that works with both.

@yrong
Copy link
Author

yrong commented Sep 11, 2019

@ry Thanks for the example. since deno is based on V8 I regard deno as javascript runtime rather a new language. But from your demo seems there is some difference in the core api (Process.env vs Demo.env). Is there any table of api comparison between the two? Say if I want to migrate the elasticsearch javascript driver from node module to deno module. What should I do?

@kitsonk
Copy link
Contributor

kitsonk commented Sep 12, 2019

V8 (and JavaScript language standard) do not address a lot of common functionality we expect in a runtime. For example console is not part of JavaScript, nor is it provided by V8. So any runtime has to provide this functionality.

The general design goal is that if a runtime feature is useful for a "server side" runtime and there is an existing web platform standard (or an emergent standard that is likely to be adopted) Deno will implement that.

When there isn't a standard, but there is a requirement to tightly bind to the host system, those APIs are exposed in the Deno namespace. We try to deliver an API in that namespace that is logical, based on the best practices and common conventions of other languages, utilising modern JavaScript conventions and structures.

If that tight binding is not required, we try to deliver the API as part of the deno_std library, which should take strong design considerations from GoLang, but follow modern JavaScript conventions and structures.

So as stated, express interop with Node.js isn't a primary design consideration, but #2644 is designed to think about how we can make that easier. A table of comparison, or scripts that help migration are certainly valid ideas about how to address it, though it hasn't yet been the focus of the "core" team. Doesn't mean the wider community hasn't thought more about it though yet.

@FredKSchott
Copy link

FredKSchott commented Sep 19, 2019

If it helps your use-case, Pika CDN (update: now Skypack) is a CDN for ESM npm packages. It will bundle up and serve any ESM package (/w dependencies) as a single JS file, with any internal common.js & node-isms removed. You can learn more here: https://www.skypack.dev/

packd-es is another option with a similar purpose: https://github.com/webcomponents-dev/packd-es

@Soremwar
Copy link
Contributor

For future reference, I maintain a repository that lists available NPM libraries and their definition files for its use with TypeScript. Feel free to add suggestions for packages in the repo below.

https://deno.land/x/types/
https://github.com/Soremwar/deno_types

@lucacasonato
Copy link
Member

lucacasonato commented Aug 13, 2020

I will close this as there are quite a few userland solutions to this:

If anyone wants to round these up as a page in the manual, that would be great (part of #6844).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants