Git Product home page Git Product logo

Comments (5)

piscisaureus avatar piscisaureus commented on May 11, 2024

This works in Deno Deploy if you use application/javascript. So the example you just linked to does actually work in Deploy.
However dynamically importing a typescript class won't work currently, because in Deploy the typescript compiler isn't available at run-time.

from deno.

mcgear avatar mcgear commented on May 11, 2024

ahh, thank you. So i just need to transpile it first in theory? Is their any plan to support Deno Deploy typescript compiling at run time?

from deno.

mcgear avatar mcgear commented on May 11, 2024

What would be the best way to transpile at runtime? esbuild wasm? Or is there something else?

from deno.

mcgear avatar mcgear commented on May 11, 2024

I thought a bit of my code might be useful. This is what works locally, but not in Deno Deploy:

  const fileContents = await toText(file.Contents);

  const enc = base64.encodeBase64(fileContents);

  const apiUrl = `data:application/typescript;base64,${enc}`;

  const apiModule = await import(apiUrl);

  const api = apiModule.default;

from deno.

mcgear avatar mcgear commented on May 11, 2024

Alright, i was able to get this working with esbuild.

I imported the WASM module:

import * as esbuild from 'https://deno.land/x/[email protected]/wasm.js';

Then, due to issues with using workers on deno deploy, had to add a call to:

await esbuild
    .initialize({
      worker: false,
    })

Then, i was able to update my code to use transpiled TS and a javascript data url:

  const fileContents = await toText(file.Contents);

  const result = await esbuild.transform(fileContents, { loader: 'ts' });

  const enc = base64.encodeBase64(result.code);

  const apiUrl = `data:application/javascript;base64,${enc}`;

  const apiModule = await import(apiUrl);

  const api = apiModule.default

from deno.

Related Issues (20)

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.