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

Fix edge compute issues with cbor-x dynamic functions #511

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

Maronato
Copy link
Contributor

While adding webauthn support to a Next.js app, I kept getting the following error during build:

../../../node_modules/.pnpm/cbor-x@1.5.2/node_modules/cbor-x/decode.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Import trace for requested module:
../../../node_modules/.pnpm/cbor-x@1.5.2/node_modules/cbor-x/decode.js
../../../node_modules/.pnpm/cbor-x@1.5.2/node_modules/cbor-x/encode.js
../../../node_modules/.pnpm/@simplewebauthn+server@9.0.0/node_modules/@simplewebauthn/server/esm/deps.js
../../../node_modules/.pnpm/@simplewebauthn+server@9.0.0/node_modules/@simplewebauthn/server/esm/registration/verifications/verifyAttestationAndroidKey.js
../../../node_modules/.pnpm/@simplewebauthn+server@9.0.0/node_modules/@simplewebauthn/server/esm/registration/verifyRegistrationResponse.js
../../../node_modules/.pnpm/@simplewebauthn+server@9.0.0/node_modules/@simplewebauthn/server/esm/index.js

Turns out cbor-x declares some dynamic functions that are not compatible with Vercel's edge compute and Cloudflare workers (info).

Thankfully, fixing it is fairly straighforward. cbor-x exports a version of itself without these eval statements via cbor-x/index-no-eval

I tested the change locally by changing the cbor import line in my node_modules to be
export * as cborx from 'cbor-x/index-no-eval';
and it fixed the issue.

The Deno import can continue pointing to the regular export since it supports eval.

PS: a few months ago I merge a PR here for something related - lack of support for streaming APIs in serverless environments. That has since changed, so importing from cbor-x/index instead of cbor-x/encode isn't an issue anymore.

Copy link
Owner

@MasterKale MasterKale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome back @Maronato! Thank you again for helping the library track changes in Vercel. CI is happy so this seems fine for me to merge and release :shipit:

@MasterKale MasterKale added the package:server @simplewebauthn/server label Jan 26, 2024
@MasterKale MasterKale added this to the v9.0.1 milestone Jan 26, 2024
@MasterKale MasterKale merged commit 91bb9f0 into MasterKale:master Jan 26, 2024
2 checks passed
@MasterKale
Copy link
Owner

@Maronato This fix is now live in @simplewebauthn/server@9.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:server @simplewebauthn/server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants