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

🚀 Feature Request: [Wrangler] implement nodeJsCompatModule support #3569

Closed
petebacondarwin opened this issue Jul 7, 2023 · 1 comment
Labels
enhancement New feature or request node compat Relating to the differences between the Workers environment and Node wrangler Relating to the Wrangler CLI tool

Comments

@petebacondarwin
Copy link
Contributor

Describe the solution

This new workerd module type instructors the runtime to enter a "node.js compatibility" mode when executing code in such modules. This includes

  • APIs available as globals (e.g. Buffer)
  • APIs accessible to require() without the node:... prefix (e.g. require("url"))

I think the basic requirement is to add a new "rule type" to Wrangler that is nodeJsCompatModule.

One difficulty will be to determine the Mime type to map it to, since the upload HTTP Form requires each module to have a mime type. See

export function toMimeType(type: CfModuleType): string {
switch (type) {
case "esm":
return "application/javascript+module";
case "commonjs":
return "application/javascript";
case "compiled-wasm":
return "application/wasm";
case "buffer":
return "application/octet-stream";
case "text":
return "text/plain";
default:
throw new TypeError("Unsupported module: " + type);
}
}

This will need to be agreed with EWC so that it can determine what module type to use when deploying the modules to the edge.

But I think this work could be completed before the EWC work, since it is entirely opt-in. We would just delay documenting it until it is ready end to end.

@petebacondarwin petebacondarwin added enhancement New feature or request node compat Relating to the differences between the Workers environment and Node wrangler Relating to the Wrangler CLI tool labels Jul 7, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jul 7, 2023
@mrbbot mrbbot moved this from Untriaged to Backlog in workers-sdk Oct 2, 2023
@penalosa
Copy link
Contributor

Closing since the nodejs_compat flag is the new way forward here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request node compat Relating to the differences between the Workers environment and Node wrangler Relating to the Wrangler CLI tool
Projects
None yet
Development

No branches or pull requests

2 participants