enonic / doc-xp

Enonic XP > 7.0 Reference Documentation
2 stars 4 forks source link

Add examples of what happens for relative require paths #343

Open sigdestad opened 3 years ago

sigdestad commented 3 years ago

AFAIK this has a resolution pattern of some kind (locally first, then within /lib etc..) https://developer.enonic.com/docs/xp/stable/framework/globals#require

rymsha commented 2 years ago

It is said on the page you linked

If the path is relative then it will start looking for the file from the local directory

It also says

The function implements parts of the CommonJS Modules Specification

And one who is familiar with it can know that

Relative identifiers are resolved relative to the identifier of the module in which "require" is written and called.

So, it is explained at least twice how relative paths are resolved.

BTW, there is no lookup in anywhere else (/lib etc...) as it would be against CommonJS Modules Specification