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

🐛 BUG: [node_compat] No matching export in "node-modules-polyfills:crypto" for import "randomInt" #4825

Closed
dtinth opened this issue Jan 23, 2024 · 1 comment
Labels
bug Something that isn't working

Comments

@dtinth
Copy link

dtinth commented Jan 23, 2024

Which Cloudflare product(s) does this pertain to?

Wrangler

What version(s) of the tool(s) are you using?

3.23.0

What version of Node are you using?

21.5.0

What operating system are you using?

Mac

Describe the Bug

Using node_compat, 3rd party dependencies that use crypto’s randomInt fails to compile.

Note that randomInt was added in Node.js v14.10.0, v12.19.0. However, rollup-plugin-node-polyfills has not been updated in 5 years.

This prevented me from deploying an Elysia.js app to Cloudflare Workers.

Minimal repro:

import { Elysia } from 'elysia';

export interface Env {}

const app = new Elysia({ aot: false }).get('/', () => 'Hello Elysia');

export default {
	async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
		return app.fetch(request);
	},
};

Expected: wrangler dev works fine.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

> wrangler dev

 ⛅️ wrangler 3.23.0
-------------------
▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.


✘ [ERROR] No matching export in "node-modules-polyfills:crypto" for import "randomInt"

    node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/elysia/dist/ws/index.js:1:50:
      1 │ ... as t}from"../error";import{randomInt as r}from"crypto";export c...
        ╵                                ~~~~~~~~~


╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit                                                                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

✘ [ERROR] Failed to build


If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose

Relevant issue on Elysia.js side

Current workaround is to downgrade Elysia to 0.8.8.

@dtinth dtinth added the bug Something that isn't working label Jan 23, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jan 23, 2024
@mrbbot
Copy link
Contributor

mrbbot commented Jan 24, 2024

Hey! 👋 Thanks for reporting this. As you point out, the node_compat polyfills we're currently using haven't been updated in a while. There's a PR up to bump these to more maintained versions (#3832), but we deemed it to be a breaking change requiring further thought. Our team got pulled into high priority internal work towards the end of last year, so fell behind on regular maintenance here.

For now, I'd recommend downgrading your dependency, or if you can, try out the nodejs_compat compatibility flag instead of the node_compat option. This uses Node.js support built-in to the runtime as opposed to polyfills, and has a different set of supported APIs. See https://main.workers-nodejs-support.pages.dev/ for an approximate compatibility matrix.

I'm going to close this issue though, since there is a workaround, and the limitations of our current node_compat solution are tracked elsewhere.

@mrbbot mrbbot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2024
@github-project-automation github-project-automation bot moved this from Untriaged to Done in workers-sdk Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
Development

No branches or pull requests

2 participants