docusign-esign-node-client icon indicating copy to clipboard operation
docusign-esign-node-client copied to clipboard

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

Open sjkcodes opened this issue 2 years ago • 15 comments

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?

sjkcodes avatar Aug 15 '23 17:08 sjkcodes

I guess the docusign-esign package was damaged so the src/ApiClient file no longer exists. Could you please remove the current package and reinstall the latest version in your application?

ByungjaeChung avatar Aug 16 '23 05:08 ByungjaeChung

I've confirmed that I'm on the latest version 6.3.0 and the src/ApiClient file exists in node_modules

sjkcodes avatar Aug 17 '23 19:08 sjkcodes

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!

ByungjaeChung avatar Aug 18 '23 02:08 ByungjaeChung

Getting the same issue here using next 14. Did you manage to get it work ?

I can confirm that nextjs has the ability the define backend api routes with a nodejs runtime.

romariclaurent avatar Oct 31 '23 15:10 romariclaurent

I'm using Next and I'm getting this same exact error when migrating from the pages router to the app router. Importing docusign-esign in the app router (in a route.ts file, which only executes on the server side) causes this Can't resolve 'ApiClient' Did you mean './ApiClient'? error.

I tried this on Next 13 and Next 14 and encountered the same issue on both.

I tried to solve this by fiddling with webpack resolver aliases: (https://webpack.js.org/configuration/resolve/#resolvealias), and was able to make the error change to Can't resolve 'Configuration' or various other modules, but was ultimately unable to make this work. Any help is appreciated

nicolassanmar avatar Nov 01 '23 19:11 nicolassanmar

I think that the issue might come from these lines of code: https://github.com/docusign/docusign-esign-node-client/blob/e54536ac33f339fdff3fe695d774d830e333a0e1/src/index.js#L11-L18

I'm not really sure, but I think that in the pages router the else if condition gets executed (which works), while the if condition gets executed on the app router (which does not work)

nicolassanmar avatar Nov 03 '23 14:11 nicolassanmar

@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!

nicolassanmar avatar Nov 07 '23 17:11 nicolassanmar

Same issue here with Next.js 14 using pages router.

thutter avatar Feb 27 '24 16:02 thutter

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.

renanadstest avatar Apr 01 '24 15:04 renanadstest

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.

jamespdaubert avatar May 06 '24 16:05 jamespdaubert

Thanks, @nicolassanmar, for providing a solution here! I really appreciate your help in resolving this issue for our SDK users.

@sjkcodes @romariclaurent, can you please confirm if you've been able to resolve the issue you were facing, or are you still encountering problems?

sonawane-sanket avatar Jun 04 '24 15:06 sonawane-sanket

@sonawane-sanket I am no longer facing issues after adding the above. However, at the very least, I think documentation should be updated to reflect this limitation. This solution was difficult to track down, and without finding it, I would not have been able to use DocuSign with NextJS.

jamespdaubert avatar Jun 04 '24 17:06 jamespdaubert

I am facing this issue as well, can the documentation be updated to help us understand how to write a NextJS API route that uses docusign-esign? This is still unclear to me

arheinjohnson avatar Jun 11 '24 18:06 arheinjohnson

I solved this issue by creating a server component with "use server" on the top of the page. I was using nextjs 14 and had docusign esign version 8.0.1.

I also updated my next.congif.mjs file to include experimental: { serverComponentsExternalPackages: ['docusign-esign'] },

ritzcod3 avatar Dec 13 '24 02:12 ritzcod3

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;

bayurzxsmtp avatar Dec 17 '24 13:12 bayurzxsmtp