Failed module resolutions using `pg` and Drizzle
Hi there, I'm using this Remix template, which works well on its own, but when I attempt to use the
pg
package to interface with my remote Postgres database, Miniflare is suddenly unable to resolve a number of dependencies after Remix finishes building.
Reproduce
1. npx create-remix@latest directory-name --template https://github.com/remix-run/remix/tree/main/templates/cloudflare-workers
2. cd directory-name
3. npm install pg drizzle-orm
4. npm install --save-dev @types/pg
4. Create an app/store.server.ts
:
7. And import it in a route:
8. npm run dev
- see above errors
platform: node
Naturally, I would like to not build for Node and be forced to use node_compat, but complying with the previous error anyway yields the following:
1 Reply
I've managed to get the server to start successfully (with a warning about duplicate object keys being generated in the build, for some reason) by polyfilling the missing modules in
remix.config.js
: and by enabling node_compat
in wrangler.toml.
So while this does allow the server to start, once the Pool
is actually created, I receive the following:
✘ [ERROR] Error: Node.js net module is not supported by JSPM core outside of Node.js
What can I do about this? I assume this is because of my polyfilling, can I do this without polyfilling?
Resolved the issue by switching to postgres
over pg
. It's relatively drop-in since I'm using drizzle. Just hoping it'll work properly outside of the local environment - I was using pg
because the drizzle documentation uses it in the Workers example.