docusign-esign-node-client: Module not found: Can't resolve 'ApiClient' in '\node_modules\docusign-esign\src' When running SERVER-SIDE

HI there,

I’m getting Module not found: Can't resolve 'ApiClient' in '\node_modules\docusign-esign\src' from my API route.

I see that this error is normally associated with users trying to run the client from the browser, but my code is definitely server-side.

I’m using NextJS 13.

Anyone else encountering this issue?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 7
  • Comments: 15 (1 by maintainers)

Most upvoted comments

@sjkcodes @romariclaurent I was able to fix this by adding the following to the next.config.js file:

module.exports = {
      ...
      experimental: {
        serverComponentsExternalPackages: ['docusign-esign'],
      },
}

Unfortunately, now I’m getting other errors that are preventing me from migrating to the app router, but might fix your problem!

As @nicolassanmar added in Nov 7th answer serverComponentsExternalPackages should be provided in your next.config.js in case you want to use our SDK with Next.js. Don’t forget to import docusign-esign library with require (CommonJS) not with import (ESM). More can be seen in Next.js documentation about this option.

Based on my knowledge, NextJS is used as a Frontend framework, not a server-side. I found this post that addresses this issue on NextJS official page: https://nextjs.org/docs/messages/module-not-found#the-module-youre-trying-to-import-is-not-installed-in-your-dependencies

Hope this helps!

I followed what nicolassanmar said above:

@sjkcodes @romariclaurent I was able to fix this by adding the following to the next.config.js file:

module.exports = {
      ...
      experimental: {
        serverComponentsExternalPackages: ['docusign-esign'],
      },
}

Unfortunately, now I’m getting other errors that are preventing me from migrating to the app router, but might fix your problem!

And also had “other errors” – namely, when running npm run build it would fail on linting (after successfully compiling). Changing my import statement from

import docusign from 'docusign-esign';

to

const docusign = require('docusign-esign');

fixed it and got my code compiling, as renanadstest suggested above.

This worked for me

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  serverExternalPackages: ['docusign-esign'],
  // Remove the experimental wrapper and directly use serverExternalPackages
};

export default nextConfig;