Can I create an alias so npm packages that use node core modules to use the 'node:xxx' instead?

I’m trying to use some npm packages (csv-parse for example) in workers. The package use the stream node API and requires stream. The cloudflare docs say that everything must require node:stream.

Is there anyway to force these external packages to import from node:stream (or similar core APIs) instead of stream?

I’ve stumbled through trying to get my tsconfig to alias paths for me but that’s not working. Similarly module-alias doesn’t seem to do the trick either.

How can we use npm packages that haven’t updated to import/require from the node: set of core APIs?

Old ask but I went through all of these steps myself and haven’t seen any mentions of what I finally got working. I used patch-package to change the require to “node:stream” myself. Not ideal, but it is an option when everything else fails.

2 Likes