lumio
lumio•4d ago

NPM package "pg@8.16.0" does not define an export ".".

Hello everyone! I'm relatively new to the deno world and am currently trying to create a simple CRUD API with Fresh. I followed this article: https://deno.com/blog/build-database-app-drizzle and installed pg with deno install npm:pg. However when trying to import it in any form from
import { Pool } from "pg"; // or "npm:pg"
// or
import pg from "pg"; // or "npm:pg"
import { Pool } from "pg"; // or "npm:pg"
// or
import pg from "pg"; // or "npm:pg"
my VSCode prints out an error saying NPM package "pg@8.16.0" does not define an export ".". Does anyone know how to fix this or work around this?
Deno
Build a Database App with Drizzle ORM and Deno | Deno
Using an object-relational mapping (ORM) database can make working with persistent data simpler. Here's how to use a popular ORM, Drizzle, with Deno.
16 Replies
foobar
foobar•4d ago
This works
import { Client } from 'npm:pg'
const client = new Client()
await client.connect()

try {
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
} catch (err) {
console.error(err);
} finally {
await client.end()
}
import { Client } from 'npm:pg'
const client = new Client()
await client.connect()

try {
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
} catch (err) {
console.error(err);
} finally {
await client.end()
}
lumio
lumioOP•4d ago
Sadly same issue So basically it is working, however, VSCode somehow has an issue with the import itself
Mr.Possumz
Mr.Possumz•4d ago
Have you tried restarting the deno lsp since adding the imports? can you also post your deno.json imports section?
lumio
lumioOP•4d ago
I did restart VSCode multiple times. Not sure if that also restarts the lsp
{
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
"@bronti/argon2": "jsr:@bronti/argon2@1.0.3",
"@types/pg": "npm:@types/pg@^8.15.2",
"drizzle-kit": "npm:drizzle-kit@^0.31.1",
"drizzle-orm": "npm:drizzle-orm@^0.43.1",
"pg": "npm:pg@^8.16.0",
"preact": "https://esm.sh/preact@10.22.0",
"preact/": "https://esm.sh/preact@10.22.0/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
"tailwindcss": "npm:tailwindcss@3.4.1",
"tailwindcss/": "npm:/tailwindcss@3.4.1/",
"tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js",
"$std/": "https://deno.land/std@0.216.0/",
"@utils/": "./utils/",
"@domain/": "./domain/",
"@services/": "./services/"
}
}
{
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
"@bronti/argon2": "jsr:@bronti/argon2@1.0.3",
"@types/pg": "npm:@types/pg@^8.15.2",
"drizzle-kit": "npm:drizzle-kit@^0.31.1",
"drizzle-orm": "npm:drizzle-orm@^0.43.1",
"pg": "npm:pg@^8.16.0",
"preact": "https://esm.sh/preact@10.22.0",
"preact/": "https://esm.sh/preact@10.22.0/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
"tailwindcss": "npm:tailwindcss@3.4.1",
"tailwindcss/": "npm:/tailwindcss@3.4.1/",
"tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js",
"$std/": "https://deno.land/std@0.216.0/",
"@utils/": "./utils/",
"@domain/": "./domain/",
"@services/": "./services/"
}
}
Mr.Possumz
Mr.Possumz•4d ago
I'd imagine restarting vscode does restart the lsp but just in case let's try. You can use cmd+shift+p to bring up vscode commands. If you're on windows it's ctrl+shift+p I believe. Then type in Deno restart and it show show an option to restart to lsp
lumio
lumioOP•4d ago
This fixes it though:
// @ts-types="npm:@types/pg"
import { Pool } from "npm:pg";
// @ts-types="npm:@types/pg"
import { Pool } from "npm:pg";
Mr.Possumz
Mr.Possumz•4d ago
what version of deno are you using?
lumio
lumioOP•4d ago
deno 2.3.1 upgrading to 2.3.3 got the same issue
Mr.Possumz
Mr.Possumz•4d ago
strange, yeah your vscode just isnt recognizing the types for some reason. Not sure what would cause that
lumio
lumioOP•4d ago
Ah I think I see the potential error
Mr.Possumz
Mr.Possumz•4d ago
whatcha got?
lumio
lumioOP•4d ago
"@types/pg": "npm:@types/pg@^8.15.2",
"pg": "npm:pg@^8.16.0",
"@types/pg": "npm:@types/pg@^8.15.2",
"pg": "npm:pg@^8.16.0",
version mismatch maybe?
Mr.Possumz
Mr.Possumz•4d ago
shouldn't be. I'm using the same locally and have no issue it's resolving 8.16 for pg and 8.15.2 for types
lumio
lumioOP•4d ago
and @types/pg is actually the latest exactly ah ok, changing that kind of brought the error back 😂
Mr.Possumz
Mr.Possumz•4d ago
lol crazy question. Your deno vs code extension is up to date as well?
lumio
lumioOP•4d ago
let me check ... however, manually restarting deno language server seems to be working I'll check the vs code extension and also restart vscode itself Deno 3.44.2 seems to be up to date I think manually restarting the LSP did the trick Thanks for your help guys 🙂

Did you find this page helpful?