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

Add a node compilation target #59864

Open
buergerling opened this issue Jan 8, 2025 · 3 comments
Open

Add a node compilation target #59864

buergerling opened this issue Jan 8, 2025 · 3 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-enhancement A request for a change that isn't a bug web-dart2js

Comments

@buergerling
Copy link

buergerling commented Jan 8, 2025

dartjs compiles for use in the browser by making use of the self property. Running on node requires the manual addition of a preamble, which is an unacceptable procedure and runs counter to the purpose of a compiler. The user of the compiler cannot know what other problems need to be solved for execution on the node platform. Dart is advertised as a language that can also be executed on the server side. This issue is particularly relevant for serverless execution.

@dart-github-bot
Copy link
Collaborator

Summary: Users need a Node.js compilation target for dartjs. Currently, Node.js support requires manual preambles, hindering server-side and serverless use.

@dart-github-bot dart-github-bot added area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Jan 8, 2025
@bivens-dev
Copy link

bivens-dev commented Jan 10, 2025

Personally, rather than just trying to target Node specifically I would much much much rather see Dart target WASI (Web Assembly not in the browser) so that you could just import dart code like a standard library in Node, Rust, Go, C#, Ruby and a bunch of others without having to worry about preambles and a bunch of other concerns.

The WASI community is getting relatively close AFAIK to finalizing the stable 1.0 release of WASI and its corresponding cross language module format.

there is an existing issue for this here if you’re interested: #56366 and another one here: #53884

@nshahan
Copy link
Contributor

nshahan commented Jan 10, 2025

Unfortunately the Dart web team does not currently have plans to support node as a compilation target out of the box. That said, there are packages from the community that help make this easier including:

The Sass compiler https://github.com/sass/dart-sass has made use of these packages to produce a node module. Sass and other projects using these node Dart packages could serve as useful examples.

Dart is advertised as a language that can also be executed on the server side.

If you are referring to the dart compile js --server-mode flag it compiles without the dart:html library to produce JavaScript that doesn't contain any references to the browser DOM APIs to avoid errors when running the code in environments outside of a browser.

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-enhancement A request for a change that isn't a bug web-dart2js
Projects
None yet
Development

No branches or pull requests

5 participants