Git Product home page Git Product logo

dart-worker-hello-world's Introduction

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.

dart-worker-hello-world's People

Contributors

bootstraponline avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.