denoland / deno_emit

Transpile and bundle JavaScript and TypeScript under Deno and Deno Deploy
https://jsr.io/@deno/emit
MIT License
222 stars 23 forks source link

import not working offline, requires wasm #117

Closed marcusreese closed 1 year ago

marcusreese commented 1 year ago

Hi, is this a bug in your code or mine? It works fine for me with internet connection, but when I try re-running it offline, it fails. I used vsCode's quick fix to cache the import, but it still reaches out to the internet for the wasm file, and I tried caching that, but I wasn't able to do so.

From my file prepUiCode.ts:

import { transpile } from "https://deno.land/x/emit@0.22.0/mod.ts";

const singleUiEntryPoint = "tempGenerated/ui.loadAll.ts";
await Deno.writeTextFile(singleUiEntryPoint, loadLines.join("\n"));
const emittedFileUrlsAndContents = await transpile(singleUiEntryPoint); // line 352

Here's the failure message when running offline:

error: Uncaught (in promise) TypeError: error sending request for url (https://deno.land/x/emit@0.22.0/emit_bg.wasm): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known const wasmResponse = await fetch(wasm_url); ^ at eventLoopTick (ext:core/01_core.js:166:11) at async mainFetch (ext:deno_fetch/26_fetch.js:266:12) at async fetch (ext:deno_fetch/26_fetch.js:490:7) at async instantiateModule (https://deno.land/x/emit@0.22.0/emit.generated.js:491:28) at async https://deno.land/x/emit@0.22.0/emit.generated.js:444:27 at async instantiate (https://deno.land/x/emit@0.22.0/emit.generated.js:422:11) at async transpile (https://deno.land/x/emit@0.22.0/mod.ts:229:38) at async _runDenoCompiler (file:///Users/marcusreese/Documents/mvp/_src/prepUiCode/prepUiCode.ts:352:38)

marcusreese commented 1 year ago

I see someone else had a similar issue: https://github.com/denoland/deno/issues/16521#issuecomment-1308189836 says, "it doesn't work offline" about another library that uses wasm, so I'm guessing this is just how Deno emit works right now. It was working for me before I upgraded Deno, but I guess it couldn't be maintained. I'm sure it was marked unstable, but I thought I needed it at the time. I guess I'll have to look at my code again and see if there's an alternative I missed. I'm sure someone has a clever workaround, but this is probably not the main forum for that.

ayame113 commented 1 year ago

Now that the Cache API and Deno KV have been implemented, wouldn't it be feasible to support offline wasm loading?

Edit: Oh, there was already an issue and PR to implement it. https://github.com/denoland/wasmbuild/issues/67 https://github.com/denoland/wasmbuild/pull/68