How to fix the dynamic needs of third-party libraries?

My desktop application uses the Electron + React method for the interface and Edge.js to connect Node to my C # application.

My problem : Webpack cannot bind my application because the Edge.js dependency causes the following error :

Critical Addiction: A dependency request is an expression

The problem is that Edge.js requires the following dynamic:

var compilerName = 'edge-' + language.toLowerCase();
var compiler = require(compilerName);

In most cases it compilerNamewill be translated to "edge-cs", but Webpack cannot determine this.

How can I solve this problem? People suggest setting require context or ContextReplacementPlugin , but both of them are usually used when you have one require('./directory/' + variable), and I don’t know how to use them in my case when I have one require(variable).

Note. I need a solution in which I do not need to change the code of my third-party library.

+4
source share
1 answer

I do not think that's possible. Did you consider something like a massive switch below? Offered here

switch (name) {
  case 'a': return require('./a');
  case 'b': return require('./b');
  // etc...
}
+1
source

Source: https://habr.com/ru/post/1689655/


All Articles