modules icon indicating copy to clipboard operation
modules copied to clipboard

import.meta.resolve consensus discussion

Open guybedford opened this issue 5 years ago • 6 comments

I've just opened the PR in https://github.com/nodejs/node/pull/31032 for import.meta.resolve support.

This is something there have been browser discussions around for quite a while, so I've reached out to those working on this there on this feature to ensure that whatever is done here can align between the platforms.

Specifically, we don't want either Node.js or the browser shipping something the other won't want to implement.

guybedford avatar Dec 19 '19 21:12 guybedford

Once we decide on API and semantics, I'd love to build it in https://npmjs.com/resolve as well.

ljharb avatar Dec 19 '19 22:12 ljharb

I'll be rather busy in the next week as will several others I'm sure so we might want to setup a timeline to avoid this being under reviewed and/or just give a clear timeline when the discussion is over so that we don't merge too quickly after discussion ends.

bmeck avatar Dec 19 '19 23:12 bmeck

this is maybe related https://github.com/nodejs/node/issues/31120

frank-dspeed avatar Dec 28 '19 13:12 frank-dspeed

@frank-dspeed can you please elaborate with examples of using import.meta.resolve per your custom loader? I think it may be relevant but I don't want to assume from my end.

Note — node's ESM module loader does not directly support https: but a custom loader doing it is a subtle difference to consider imho.

SMotaal avatar Jan 09 '20 14:01 SMotaal

@SMotaal my loader would simply extract all imports and pass them to import.resolve if needed but at present my esm-loader has node esm module resolve already it only can't handle relative urls thats where import resolve can help at present i would use import meta url and resolve relativ to that.

frank-dspeed avatar Jan 10 '20 12:01 frank-dspeed

i have a exra helper that i call resolvePath()

// gets called with a import.meta.url returns path 
export function resolvePath(url){
    return urlToPath(url)
}

i import that helper into any module and call it with the modules import.meta.url to retrive relativ path to current module

frank-dspeed avatar Jan 10 '20 12:01 frank-dspeed