(Code below is a simple example, real scenario is bigger)
I have two modules, mod1.js
and mod2.js
, which are bundled together (using esbuild). They share a common dependency, util.js
.
Problem is: when code in mod2.js
imports util.js
(using same alias), there's a conflict with names.
util.js
:
export class Util {
...
}
mod1.js
:
import Util from "./util.js";
...
mod2.js
:
/* this raises an error of variable already declared */
import Util from "./util.js";
...
If I change alias in mod2.js
, error goes away, as expected. But changing aliases every time I import util.js
is a bit clumsy, and makes me think there has to be another way.
Is there a better approach to point to a common dependency from multiple modules which are bundled together?
Thanks in advance!