π Quickstart throws an error in Deno deploy
brettimus opened this issue Β· comments
Environment information
Supabase functions (Deno deploy edge functions) with supabase cli v1.77.9
What happened?
Importing autometrics via import { autometrics } from "https://esm.sh/autometrics@0.5.0";
and wrapping a simple function gave me the following error:
[Info] Autometrics: Initiating a Prometheus Exporter on port: 9464, endpoint: /metrics
[Error] TypeError: (0 , re.createServer) is not a function
at new r (https://esm.sh/v128/@opentelemetry/exporter-prometheus@0.41.0/esnext/exporter-prometheus.mjs:18:1309)
at getMetricsProvider (https://esm.sh/v128/@autometrics/autometrics@0.5.0/esnext/autometrics.mjs:4:2276)
at getMeter (https://esm.sh/v128/@autometrics/autometrics@0.5.0/esnext/autometrics.mjs:4:2387)
at https://esm.sh/v128/@autometrics/autometrics@0.5.0/esnext/autometrics.mjs:4:3459
at Server.<anonymous> (file:///home/deno/functions/rabbit/index.ts:15:26)
Expected result
I would expect a friendlier error message instead of a runtime Type error
Thanks for reporting this @brettimus! I need to update the quickstart for Deno-specific instructions. Just to validate that this works can you try importing autometrics
with an npm
specifier and let me know if that works?
So:
import { autometrics } from "npm:autometrics"
so yeah the issue here is npm
specifiers still don't work with Deno deploy (support should be coming this year)
a deno script run with an npm:autometrics
import does indeed work
This might be more of a hackday-type kind of suggestion, but we could consider using https://github.com/denoland/dnt instead. Then we'd build the library to be Deno-first, and let them generate the NPM packages for us. It's actually an easier setup altogether, assuming the NPM compatibility doesn't fail us...
oh Deno's dnt
looks interesting - I'm tempted π. We use some Node-specific APIs in the libraries that get polyfilled in Deno - I wonder how that will play along with it
If I understand correctly, dnt
will polyfill it the other way around, so if you use Deno-specific APIs instead of the Node-specific APIs, it will still make sure it works well as an NPM package too. It might even work out-of-the-box with Node-specific APIs if you use npm:
and node:
prefixes internally, but then you probably will still run into the same issues with Deno deploy as you have now. But yeah, it might warrant some experimentation :)