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

How to compile Deno modules to Node.js modules? #4528

Closed
KSXGitHub opened this issue Mar 30, 2020 · 8 comments
Closed

How to compile Deno modules to Node.js modules? #4528

KSXGitHub opened this issue Mar 30, 2020 · 8 comments

Comments

@KSXGitHub
Copy link
Contributor

KSXGitHub commented Mar 30, 2020

I have tried various bundlers (parcel, webpack, rollup, @pika/pack), they all share the same limitation: They do not recognise remote module URLs.

@ondras
Copy link
Contributor

ondras commented Mar 30, 2020

@KSXGitHub
Copy link
Contributor Author

@ondras

hat about https://github.com/rollup/plugins/tree/master/packages/url ?

I had read about it before. Its function is not to convert remote URLs to es modules, but to allow importing non-JavaScript assets. I need something that converts remote modules (such as https://deno.land/std/flags/mod.ts) to something that Node.js can use.

@ondras
Copy link
Contributor

ondras commented Mar 30, 2020

I see.

And what particular behavior are you looking for? Do you want your remote dependencies downloaded+cached+bundled, or resolved at runtime (i.e. replacing import "http..." statements with something like requireRemote("http...") ?

@KSXGitHub
Copy link
Contributor Author

@ondras I want to download and resolve at compile time. I only want to create one file (bundle).

@nayeemrmn
Copy link
Collaborator

What's wrong with deno bundle? It'll work with any Deno module including those written to be Node compatible, right?

@KSXGitHub
Copy link
Contributor Author

@nayeemrmn I tried again with deno bundle, it didn't work initially due to Node.js (v13.12.0) does not support optional chaining syntax (line 12 of the bundle). Then I tried harder by using babel, it works now. It would be nicer if I can define tsconfig from the command line, is there an issue about this already?

@KSXGitHub
Copy link
Contributor Author

@nayeemrmn Another thing, how to create *.d.ts files from Deno TypeScript files?

@kitsonk
Copy link
Contributor

kitsonk commented Mar 30, 2020

@KSXGitHub Deno.bundle() would give you the same output as deno bundle and allows you to pass options that would target es2020 or es2019. The problem is you would have to write out the output yourself.

As far as types, see #3385. I've tried to do it recently. It is complicated because of the way the TypeScript compiler generates the declaration files for bundles means effectively it doesn't work. I need to basically handcraft a bundle .d.ts based on each module and then output it.

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

4 participants