SignNowNodeSDK icon indicating copy to clipboard operation
SignNowNodeSDK copied to clipboard

Dynamic require in config/index.js breaks compatibility with esbuild

Open Matt561 opened this issue 3 years ago • 0 comments

Hi there,

I'm currently trying to incorporate the SignNowSDK into a project that is using esbuild.

Unfortunately, it seems that setEnvConfig() uses dynamic require() statements that are causing our build to fail.

const setEnvConfig = env => {
  if (env) {
    currentEnvironment = env;
    return Object.assign(currentConfig, require(`./${env}/`));
  }

  return Object.assign(currentConfig, require(`./${currentEnvironment}`));
};

A quick and easy solution to this is to not use the dynamic requires statements, even if it means adding a small amount of code duplication.

const setEnvConfig = env => {

  if (env) {
    currentEnvironment = env;
    if (env === 'eval') {
      return Object.assign(currentConfig, require('./eval'));
    }
    if (env === 'prod') {
      return Object.assign(currentConfig, require('./prod'));
    }
  }

  return Object.assign(currentConfig, require(`./${currentEnvironment}`));
};

There may be a nicer way of writing this to remove the additional level of indentation from the added ifs of course but the point is we aren't using variables in the require().

Would it be possible to add this (or a better) fix to avoid dynamic require() statements? It would be a shame to fork and maintain a repo for such a small fix 👍

Thanks in advance for the feedback and/or help!

Matt561 avatar Aug 26 '22 19:08 Matt561