Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Matt561 opened this issue Aug 26, 2022 · 0 comments
Open

Comments

@Matt561
Copy link

Matt561 commented Aug 26, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant