Skip to content

cloudflare/dart-worker-hello-world

Dart hello world for Cloudflare Workers

Your Dart code in index.dart, running on Cloudflare Workers

In addition to Wrangler you will need to install Dart.

Wrangler

To generate using wrangler

wrangler generate projectname https://github.com/cloudflare/dart-worker-hello-world

Further documentation for Wrangler can be found here.

Dart

After installing Dart per the linked instructions above,

cd projectname

# run once to get dependencies
pub get

dart2js -O2 --server-mode -o index.js index.dart

That will compile your code into index.js, after which you can run wrangler publish to push it to Cloudflare.

For more information on how Dart translates to JavaScript, see the docs for dart2js and the interop guide.

Errors

Dart 2.13.0 and above require the dart2js --server-mode flag when using native JavaScript classes. Server mode is used to compile JS to run on server side VMs such as nodejs. If this flag is not used, the following errors are displayed:

index.dart:4:7:
Error: JS interop class 'Request' conflicts with natively supported class '_Request' in 'dart:html'.
class Request {
      ^
index.dart:8:7:
Error: JS interop class 'Response' conflicts with natively supported class '_Response' in 'dart:html'.
class Response {
      ^
index.dart:13:7:
Error: JS interop class 'FetchEvent' conflicts with natively supported class 'FetchEvent' in 'dart:html'.
class FetchEvent {
      ^
Error: Compilation failed.

About

Dart hello world for Cloudflare Workers

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages