yastaraus
yastaraus11mo ago

Building from `src` offline?

Hey guys! I'm new to Deno (and web dev as well to be honest), so could you help me here please. I'm making a site with the Lume (SSG for Deno), and there is the step when I need to build a site from src. It is all good when I'm connected to the internet, but when I'm turning if off — building process crushes:
deno task serve
Task serve deno task lume -s
Task lume echo "import 'lume/cli.ts'" | deno run --unstable -A - "-s"
Loading config file file:///Users/pavelzinoviev/Local-Documents/webdev/website/_config.js

TypeError: error sending request for url (https://wilsonl.in/minify-html/deno/0.10.3/index_bg.wasm): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
at async mainFetch (ext:deno_fetch/26_fetch.js:277:12)
at async fetch (ext:deno_fetch/26_fetch.js:501:7)
at async init (https://wilsonl.in/minify-html/deno/0.10.3/index.js:206:45)
at async (https://deno.land/x/lume@v1.18.4/plugins/minify_html.ts:34:1)
deno task serve
Task serve deno task lume -s
Task lume echo "import 'lume/cli.ts'" | deno run --unstable -A - "-s"
Loading config file file:///Users/pavelzinoviev/Local-Documents/webdev/website/_config.js

TypeError: error sending request for url (https://wilsonl.in/minify-html/deno/0.10.3/index_bg.wasm): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
at async mainFetch (ext:deno_fetch/26_fetch.js:277:12)
at async fetch (ext:deno_fetch/26_fetch.js:501:7)
at async init (https://wilsonl.in/minify-html/deno/0.10.3/index.js:206:45)
at async (https://deno.land/x/lume@v1.18.4/plugins/minify_html.ts:34:1)
Is that how it supposed to be? I tried to cache every module I've imported by running deno cache --reload _config.js, but it did not help. Any advice?
1 Reply
jeff.hykin
jeff.hykin11mo ago
It looks like one of the packages in the project is trying to dynamically fetch a wasm file. So unless you fork that minify-html tool, there's no way to make it work offline (on any runtime) I've run into this problem before (as a package maintainer) so I'll explain a bit about how minify-html should fix it. Deno can cache static imports, but deno (and the web), by default can't import json/wasm/css/etc files. A bad workaround is to just use fetch to dynamically download the wasm/json/css file. Then you end up with problems like this. The alternative is to escape the file to make it importable. I made a little CLI tool called binaryify that does the heavy lifting: https://deno.land/x/binaryify Just give that^ the wasm file as an argument, and it'll spit out a .js file that can be statically imported. The import has the content as the wasm file, just like if it were read from fetch, but now deno can cache it and bundle it.