Cocktail
Cocktail

Reputation: 29

Dynamic import of JavaScript module without file path

Is it possible in the ECMAScript language, or other way, to import a module using some kind of object other than the real file path in local computer (whether relative or absolute, or with an "import map")?

For example, as a use-case, there are some JavaScript packages ("memfs") that mimic files and behave like virtual filesystems. Some of those files can of course contain JS code that can play the role of a JS Module, possibly wanted to be dynamically imported. They may have a "fake" virtual file path or file name, but how can the JS Runtime/Parser/Interpreter can process it?

Also, we can simply read a local file's content (Via NodeJS for example), and it's possible that we want to load its content as a module, when the original path is not available anymore, or for any other reason.

So, sometimes you have files, file contents, but without "file path", how it's possible to use that content for a module? (and not a regular inline scoped object.

Upvotes: 0

Views: 362

Answers (0)

Related Questions