Doesn't Es Module System Guarantee Module Singleton?
Solution 1:
Yes, there is no guarantee in ECMAScript - the rules for how to resolve module specifiers are determined by the host.
Multiple different
referencingScriptOrModule
,specifier
pairs may map to the same Module Record instance. The actual mapping semantic is implementation-defined but typically a normalization process is applied to specifier as part of the mapping process. A typical normalization process would include actions such as alphabetic case folding and expansion of relative and abbreviated path specifiers.
So only your host (like node.js or the browser) will give you the guarantee that it will always resolve certain specifiers to the same module.
There are many examples where (A, "b.js")
and (C, "b.js")
should not resolve to the same module - e.g. when A
is one/a.js, it should return the module one/b.js, while C
might be two/c.js and result in the module two/b.js.
Post a Comment for "Doesn't Es Module System Guarantee Module Singleton?"