Tom RedmanT
Convex Community11mo ago
6 replies
Tom Redman

"use node" is present in node runtime file but still getting "you are using node APIs" error

In a file in which I only use actions, I'm trying to use the mailchimp npm package:

// mailchimpActions.ts
"use node";
import Mailchimp from "./mailchimpNode"; 
...


I've tried:
- putting "use node"; at the top of the file, at the top of the imported file, and every variation thereof
- putting all the Mailchimp import and classes I've created in the same file
- No other files import the mailchimp node package
- Deleting the _generated folder and re-building
- I've added the mailchimp package as an external dependency in convex.json, and then tried * to no avail:
{
  "node": {
    "externalPackages": [
      "*"
    ]
  }
}


Yet I'm still getting this error:

convex | ✘ [ERROR] Could not resolve "querystring"
convex |
convex |     node_modules/@mailchimp/mailchimp_marketing/src/ApiClient.js:18:26:
convex |       18 │ var querystring = require('querystring');
convex |          ╵                           ~~~~~~~~~~~~~
convex |
convex |   The package "querystring" wasn't found on the file system but is built into node. Are you trying
convex |   to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✖ It looks like you are using Node APIs from a file without the "use node" directive.
convex | See https://docs.convex.dev/functions/runtimes#nodejs-runtime


Here is my Mailchimp file:
"use node";

import mailchimp from "@mailchimp/mailchimp_marketing";
import type { Infer } from "convex/values";
import type { mailchimpCredentialsSchema } from "../../schemas/integrationCredentialsSchema";

class Mailchimp {
  private api: any;
  constructor({
    credentials,
  }: {
    credentials: Infer<typeof mailchimpCredentialsSchema>;
  }) {
    this.api = mailchimp;
    this.api.setConfig({
      apiKey: credentials.credentials.accessToken,
      server: credentials.credentials.serverPrefix,
    });
  }

  async getLists() {
    return await this.api.lists.getAllLists({
      includeTotalContacts: true,
    });
  }
}

export default Mailchimp;


Any ideas?
Was this page helpful?