Skip to content

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

Merged
MasterKale merged 1 commit into
MasterKale:masterfrom
Maronato:fix-cbor-index-no-eval
Jan 26, 2024
Merged

Fix edge compute issues with cbor-x dynamic functions#511
MasterKale merged 1 commit into
MasterKale:masterfrom
Maronato:fix-cbor-index-no-eval

Conversation

@Maronato

Copy link
Copy Markdown
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.

@MasterKale MasterKale left a comment

Copy link
Copy Markdown
Owner

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
@MasterKale

Copy link
Copy Markdown
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