#resend email error

16 messages · Page 1 of 1 (latest)

severe pulsar
#

What is this:

Oct 27, 11:19:05.918 A users/actions:invite [ERROR] {
  error: [Error: Couldn't resolve resend.lib.sendEmail]
}

Usage:

import { Resend as ResendAPI } from "resend";
...
let emailError: any = null;

    try {
      const resend = new ResendAPI(process.env.AUTH_RESEND_KEY);
      await resend.emails.send({
        from: "...",
        to: email,
        subject: "...",
        html: emailBody,
      });
    } catch (error) {
      emailError = error;
    }
violet krakenBOT
#

Hi @severe pulsar. 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 error message and your code, it appears there's a mismatch between the error you're seeing and the code you've shared.

The error Couldn't resolve resend.lib.sendEmail suggests that somewhere in your code, you're trying to call resend.lib.sendEmail, but this method doesn't exist in the Resend SDK.

Looking at your code snippet, you're correctly using resend.emails.send(), which is the proper Resend SDK method. However, the error indicates that somewhere else in your codebase (possibly in the users/actions:invite action), there's an incorrect reference to resend.lib.sendEmail.

How to fix this:

  1. Search your codebase for any references to resend.lib.sendEmail and replace them with resend.emails.send()

  2. Verify your import: Make sure you're importing Resend correctly:

    import { Resend } from "resend";
    
  3. Check your action code: The error is coming from users/actions:invite, so review that specific action file for any incorrect Resend method calls.

Additional considerations:

If you're using Resend with Convex Auth for email verification or password resets, the knowledge sources show that you should use the Resend SDK directly in your custom email provider configuration, as shown in the OTPs configuration and password reset setup.

Alternatively, if you want more robust email sending with queuing and batching features, consider using the Resend Convex Component, which provides additional features like durable execution and rate limiting.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@severe pulsar Kapa.ai is still learning and improving, please let me know how I did by reacting below.

severe pulsar
#

no there is no incorrect reference @violet kraken

violet krakenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I apologize for the confusion. Let me reconsider the issue.

If there's no incorrect reference to resend.lib.sendEmail in your code, the error might be related to how Convex is bundling or resolving the Resend package. Here are some potential causes and solutions:

Possible issues:

  1. Module resolution in Convex actions: The error suggests Convex is having trouble resolving the Resend module. Make sure you're using this code in a Convex action (not a mutation or query), since actions are required for external API calls.

  2. Package installation: Verify that the resend package is properly installed:

    npm install resend
    
  3. External packages configuration: You may need to add resend to the externalPackages in your convex.json file. Based on the Discord discussion about React Email with Resend, some packages need to be explicitly marked as external:

    {
      "node": {
        "externalPackages": ["resend"]
      }
    }
    
  4. Node runtime: If you're still having issues, try using the Node runtime by adding "use node"; at the top of your action file, as shown in the Discord thread about Resend with React Email.

Could you share:

  • Whether this code is in a Convex action?
  • Your convex.json configuration?
  • The full error stack trace if available?

This would help identify the exact cause of the resolution error.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@severe pulsar Kapa.ai is still learning and improving, please let me know how I did by reacting below.

severe pulsar
#

where to put convex.json?
@violet kraken

violet krakenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Based on the Convex documentation, the convex.json file should be placed in the root of your project, in the same directory as your package.json.

So if your project structure looks like this:

my-project/
├── package.json
├── convex.json          ← Place it here
├── convex/
│   └── ... (your Convex functions)
└── src/
    └── ... (your app code)

For your specific case with the Resend issue, create or update the convex.json file in your project root with:

{
  "node": {
    "externalPackages": ["resend"]
  }
}

After adding or modifying convex.json, you may need to restart your convex dev server for the changes to take effect.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@severe pulsar Kapa.ai is still learning and improving, please let me know how I did by reacting below.

severe pulsar
#

it works locally, but not in the self hosted convex deployment (docker) @violet kraken

violet krakenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Based on your situation where the code works locally but fails in your self-hosted Convex deployment (Docker), this is likely an environment-specific issue. Here are the key things to check:

1. Environment Variables

Ensure that AUTH_RESEND_KEY is properly set in your Docker deployment environment. The error might be occurring because the API key isn't available in the Docker container.

For self-hosted deployments, you need to make sure environment variables are passed to the Docker container. Check your Docker configuration to ensure the environment variable is being set.

2. External Packages in Docker

Since you've added resend to externalPackages in convex.json, the package needs to be installed on the server. According to the external packages documentation:

Packages marked as external are installed from npm the first time you push code that uses them. The version installed matches the version installed in the node_modules folder on your local machine.

In a self-hosted Docker environment, you may need to ensure:

  • The Docker container has network access to npm
  • The node_modules directory is properly synchronized
  • The package installation process can complete successfully

3. Node Runtime

Make sure your action file includes the "use node"; directive at the top, as external packages require the Node.js runtime:

"use node";

import { Resend as ResendAPI } from "resend";
// ... rest of your code

4. Docker-Specific Considerations

For self-hosted deployments, check:

  • Docker container logs for any package installation errors
  • Network connectivity from the container to external services
  • File permissions in the Docker container
  • Whether the deployment process completed successfully
#

Could you check your Docker logs for any errors during the deployment or package installation phase? This might reveal what's failing in the self-hosted environment.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: