You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importjitifrom'jiti'constmoduleAsText="export default 42"constdataUrl="data:text/javascript;base64,"+btoa(moduleAsText)constnativeImport=awaitimport(dataUrl)console.log(nativeImport.default)// prints 42constwithJiti=jiti(import.meta.filename)(dataUrl)//Throws "MODULE_NOT_FOUND" errorconsole.log(withJiti.default)
Describe the bug
jiti fails to import modules from data-urls, which is supported by node's native import
Additional context
I tested both base64 encodings and text/javascript encoding, neither worked.
Peering at the source-code there doesn't seem to be any handling for this yet. Would you be interested in supporting this?
As a temporary workaround, you can add an extension not in the extensions array[0] to the end of the URI.
This will make JITI think that it's an unsupported file type and will use the native import/require instead.
[0]: The default extensions array is: [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts", ".json"]
Example
constscript=`export default 0;// For JITI support when used as data: .unknown`;import(`data:text/javascript;charset=utf-8,${encodeURIComponent(script)}`);
Activity
bohjak commentedon Sep 21, 2024
As a temporary workaround, you can add an extension not in the extensions array[0] to the end of the URI.
This will make JITI think that it's an unsupported file type and will use the native import/require instead.
[0]: The default extensions array is:
[".js", ".mjs", ".cjs", ".ts", ".mts", ".cts", ".json"]Example