Failed to import - pg (https://www.npmjs.com/package/pg)
Failing module
- GitHub: https://github.com/brianc/node-postgres
- npm: https://npmjs.com/package/pg
import { Client } from "https://esm.sh/pg"
Error message
After running deno run I got this:
error: Uncaught SyntaxError: The requested module 'https://esm.sh/pg' does not provide an export named 'Client'
import { Client } from "https://esm.sh/pg";
^
at <anonymous> (file:///C:/Users/~/Desktop/temp/backend/src/util/postgres.ts:1:10)
After updating the import to "https://esm.sh/pg?cjs-exports=Client" I got this:
error: Uncaught Error: Could not find module root given file: "https://esm.sh/v128/[email protected]/denonext/bindings.mjs". Do you have a `package.json` file?
at Function.l.getRoot (https://esm.sh/v128/[email protected]/denonext/bindings.mjs:9:620)
at P (https://esm.sh/v128/[email protected]/denonext/bindings.mjs:7:2170)
at https://esm.sh/v128/[email protected]/denonext/libpq.mjs:9:916
at https://esm.sh/v128/[email protected]/denonext/libpq.mjs:9:452
at https://esm.sh/v128/[email protected]/denonext/libpq.mjs:9:4702
Additional info
- esm.sh version: latest?
- Deno version: 1.35.1
Does esm.sh even work with bindings actually?
Does esm.sh even work with bindings actually?
I believe no. Node gyp bindings will eventually try to use __filename / __dirname (depends on how code is written/generated by devs) and will try to load node native addon file. I think esm.sh doesn't run the build task that generates native node addon, and it would ofc depend on different cpu architecture and whether deno supports napi or not. I think it's beyond the scope of esm.sh to support native node addons.
Figured out it works using the npm:pg specifier though its missing typing's ~ also on the notes of deno supporting napi it seems like they do https://github.com/denoland/deno/pull/13633 ~ wondering now if it would be possibility for this to work on esm.sh?
This package also says it supports a pure javascript implementation without the bindings
@ije any input on this not currently able to use the npm: specifier because its not currently available on deno deploy
@bryiac i will check