Nuxt + AWS SDK + TS transpilation issue
I am using AWS JS SDK to get stuff from S3 via server on an API call. Using the client send method produces a
[nuxt] [request error] [unhandled] [500] t is not a function
. The reason I believe this to be a Cloudflare issue is because creating the application locally via nuxt build
and nuxt preview
does not produce the same issue. However, whenever I use wrangler or deploy to pages, the error occurs. However, I can't be sure and am posting here since I am more likely to get help than from cloudflare discord, and it's still nuxt related.
The trouble code:
3 Replies
Hi @BigBallard. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I don't have enough specific details to directly address your issue with AWS SDK, TypeScript transpilation, and Cloudflare. However, I can provide some insights that might be helpful in troubleshooting your Nuxt deployment issue.
1. ESM Compatibility: The error you're encountering might be related to ES Modules (ESM) compatibility issues. As mentioned in the ES Modules documentation, some libraries may not work correctly when imported by Node.js in ESM mode.
To address this, you could try adding the AWS SDK to the
build.transpile
array in your nuxt.config.ts
:
2. Default Exports: The error message "t is not a function" could be related to how the AWS SDK is being imported. As explained in the Default Exports section, there might be issues with how CommonJS modules are imported in an ESM context. You might want to try using a named import instead of a default import for the AWS SDK components.
3. Cloudflare Deployment: If the issue only occurs on Cloudflare, it could be related to how Cloudflare handles serverless functions. As mentioned in a GitHub issue about Cloudflare deployment, some libraries that work in Node.js environments might not work in serverless edge functions.
4. CDN Proxy Settings: If you're using Cloudflare, make sure to check your CDN proxy settings as mentioned in the CDN Proxy documentation. Certain Cloudflare optimizations can cause issues with Nuxt applications.
Given that the issue only occurs in the Cloudflare environment, it's likely related to how the AWS SDK is being bundled or executed in that specific runtime. You might need to investigate if there are Cloudflare-specific versions or configurations for the AWS SDK.
If these suggestions don't resolve your issue, you might need to provide more detailed error logs from your Cloudflare deployment to get more specific assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@409612844255019008> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
AWS SDK I learned is not compatable because of some libraries using @smithy dependency which in turn uses node:fs which based on this discussion makes it a no go. Gonna have to migrate to another solution
GitHub
t is not a function - when I use
@aws-sdk/client-s3
on a Cloudfla...I am pretty lost as I am not understanding where this error is coming from, I am able to get this working my S3 service working on a usual node runtime, but I just get this error t is not a functio...