nodejs compat mode problem: Uncaught Error: No such module "node:module"

nodejs compat mode does not work for me. not even hello world type code without "node: bla" type imports.
No description
11 Replies
spirobel
spirobelOP11mo ago
I added compatibility_flags = [ "nodejs_compat" ] and the dev server stopped working
Hello, I’m Allie!
If you clone this repo and install the dependencies, does it throw any errors? https://github.com/helloimalastair/compat-debug
GitHub
GitHub - helloimalastair/compat-debug
Contribute to helloimalastair/compat-debug development by creating an account on GitHub.
Hello, I’m Allie!
You can start it with npm run dev, or your package manager of choice
spirobel
spirobelOP11mo ago
interesting. no errors. the only difference I see is that this uses a wrangler.json and wrangler dev -j i didnt use the -j and i have a wrangler.toml name = "experiment-worker" main = "entrypoints/cf.js" send_metrics = false compatibility_flags = [ "nodejs_compat" ] compatibility_date = "2024-01-29" that looks like this ohhh and wrangler as a dependency instead of dev dependency lets take a look if it makes a difference
Hello, I’m Allie!
To confirm, are you using Module Syntax or Event Listener Syntax? The -j makes it look for JSON. That/whether it is a devDependency shouldn’t be the issue
spirobel
spirobelOP11mo ago
I think I found the issue: I use bun to build a package with target: "node" and it adds this to the bundle:import{createRequire as Ff} from"node:module"; just importing this package is enough to trip up wrangler my example looked something like: import { entryPoint } from "../dist/bundledwithbunthing.js"; import process from "node:process"; import { Buffer } from "node:buffer"; just the import statement at the top while still lead to the error message node:module is not supported in cf workers, right?
Hello, I’m Allie!
Looks like no. I would probably stick with the built-in bundler, or hard-code the node imports, rather than telling it to use target: node
spirobel
spirobelOP11mo ago
with deno it works. they support the node:module thing. So I can use the target node to bundle my backend and deploy it to deno. or self host. It would be nice to also deploy it to cloudflare workers. But that would mean I would have to switch to target browser and that means I would have to rewrite many things. Would it be possible to use the wrangler bundler on top of the already bundled package that was bundled for the node target?
Hello, I’m Allie!
I don’t think it nukes the module import, so no. Can you just bundle it right before upload, rather than pre-bundling?
spirobel
spirobelOP11mo ago
yes. I run a bun run build in a github action. I think I could define createRequire during the build process. https://www.npmjs.com/package/create-require but unsure if it is worth the effort. Is there a plan to catch up with deno / bun when it comes to node compatibility?
npm
create-require
Polyfill for Node.js module.createRequire (<= v12.2.0). Latest version: 1.1.1, last published: 3 years ago. Start using create-require in your project by running npm i create-require. There are 360 other projects in the npm registry using create-require.
Hello, I’m Allie!
I know there is an ongoing effort to add support for stuff, but it is probably less than Bun/Deno
Want results from more Discord servers?
Add your server