goshippo / shippo-node-client

Shipping API Node.js library (USPS, FedEx, UPS and more)
https://goshippo.com/docs
MIT License
136 stars 54 forks source link

Dynamic Code Evaluation on Vercel Edge Functions (Next.js) #94

Open robpetty opened 10 months ago

robpetty commented 10 months ago

I am in process of integrating Shippo into a project, and while everything is working fine locally, turns out the production build when deploying to Vercel fails with the Shippo Node Client. This is because the Vercel Edge Functions do not allow "new function". More detail on this is here:

https://nextjs.org/docs/pages/api-reference/edge#unsupported-apis

Checking the code base, this is done in the /lib/utils.js file:

https://github.com/goshippo/shippo-node-client/blob/5a8e140e91fea880412f47c9ac807d43c1971d81/lib/utils.js#L69

Function makeInterpolator is used in a few locations, though its not fully clear why. I am still attempting to sort other ways around it (including trying configs to allow the build, but nothing has worked yet. Vercel also mentions if they are actually hit while running on the edge, they will throw an error so even if I get it to build, that doesn't seem ideal.

https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Anyone have experience with this and if so, any workaround? Thanks!

image

robpetty commented 10 months ago

I should note I have tried adding this to my own shippo_helpers.ts file where I call into Shippo but doesn't seem to make any difference in the final error message (though I can't find much docs on these config options):

export const config = { runtime: "edge", unstable_allowDynamic: ["**/node_modules/shippo/**/*.js"], };

robpetty commented 10 months ago

For anyone else who gets stuck here is Shippo API Client Wrapper I wrote to get around this:

https://gist.github.com/robpetty/c9d895220ccdb764c346669258f09e8d