Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use nodejs_compat but still polyfill node internals that are not supported yet? #4489

Open
schettn opened this issue Nov 22, 2023 · 4 comments
Labels
nodejs compat Relating to the node runtime compatibility flag

Comments

@schettn
Copy link

schettn commented Nov 22, 2023

I'm running into a very similar issue, my workers depend on async_hooks for logging / instrumentation. I was experimenting with getting a direct PostgreSQL connection to work, instead of using a 'proxy' like Hasura, but indeed pg needs node_compat while asyncvery_hooks need nodejs_compat, and the project won't build. Are here any work arounds for this?

Edit:
@Cherry if your current use-case is using pg, an alternative that I found https://github.com/porsager/postgres, seems to be working just fine in nodejs_compat mode!

_Originally posted by @ItsWendell in cloudflare/workerd#1856

@petebacondarwin
Copy link
Contributor

We're working on a new way of getting Node.js compatibility which uses a combination of compile-time polyfills and runtime built-ins. With the latest Wrangler you could try this out by adding the experimental:nodejs_compat_v2 and leave feedback for us to stabilize this.

@schettn
Copy link
Author

schettn commented Aug 2, 2024

Seems to work. I will report if it really works after I get the service running.

My current problem is #6402

@schettn
Copy link
Author

schettn commented Aug 2, 2024

@petebacondarwin

When I use experimental:nodejs_compat_v2 I cannot deploy when using graphql-yoga. wrangler dev works fine.

import {createYoga} from 'graphql-yoga'
console.log(createYoga)

Error:

Uncaught TypeError: Cannot read properties of undefined (reading 'getBuiltinModule')
    at null.<anonymous>
  (file:///Users/schettn/Documents/pylon/pylon-template/wrangler/node_modules/unenv/runtime/node/process/$cloudflare.mjs:168:60)
    at init_cloudflare (index.js:1:303)
    at null.<anonymous>
  (file:///Users/schettn/Documents/pylon/pylon-template/wrangler/node_modules/wrangler/_virtual_unenv_global_polyfill-process.js:2:9)
    at init_virtual_unenv_global_polyfill_process (index.js:1:303)
    at null.<anonymous>
  (file:///Users/schettn/Documents/pylon/pylon-template/wrangler/src/index.ts:1:1)
   [code: 10021]

@schettn
Copy link
Author

schettn commented Aug 2, 2024

Another bug:

Screen.Recording.2024-08-02.at.16.37.53.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nodejs compat Relating to the node runtime compatibility flag
Projects
Status: Backlog
Development

No branches or pull requests

3 participants