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
{{ message }}
Repository navigation
cannot import built-ins in data: URL module #43060
If this documentation is correct, I believe it should be able to import the builtin module path successfully in a data: URL script.
What do you see instead?
$ node index.mjs node:internal/errors:465 ErrorCaptureStackTrace(err); ^TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file?[90m at new NodeError (node:internal/errors:372:5)?[39m?[90m at fileURLToPath (node:internal/url:1422:11)?[39m?[90m at checkIfDisallowedImport (node:internal/modules/esm/resolve:1061:23)?[39m?[90m at defaultResolve (node:internal/modules/esm/resolve:1189:23)?[39m?[90m at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)?[39m?[90m at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)?[39m?[90m at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)?[39m?[90m at link (node:internal/modules/esm/module_job:78:36)?[39m { code: ?[32m'ERR_INVALID_URL_SCHEME'?[39m}
Additional information
In another Node.js version, the output is as follows:
Not exactly related to your problem, but you should always encode the string you pass to be URL-friendly and avoid surprises, e.g. by passing encodeURIComponent(scriptText)) instead of scriptText.
constscriptText=`import path from 'path';export const foo = 'bar';`.trim();awaitimport(`data:text/javascript,${scriptText}`);// Wrong, only works by accident if the JS contains no URL special chars.awaitimport(`data:text/javascript,${encodeURIComponent(scriptText)}`);// Better, works all the times!
This issue is a duplicate of #42860, it has been fixed #42881, it should be backported to v16.x in the next release.
v16.16.0 doesn't have the fix (it was a security release, so it only includes the security fixes), so that's expected. It's supposed to be fixed in the next v16.x release though.
Activity
dnalborczyk commentedon May 11, 2022
@nujarum is this issue about import not working at all, or not working in v16?
depending on which, you did not (re-)export anything, if you wanted to see the module content in the console.
nujarum commentedon May 12, 2022
As far as I can tell, this issue only occurs in v16.15 (not v16.14).
I have added the table of versions I have checked.
Note that changing
pathtonode:pathmade no difference in behavior.nujarum commentedon May 12, 2022
This may be a similar issue to #42890.
dnalborczyk commentedon May 12, 2022
since you corrected the original issue now it wasn't clear to what you were referring to.
[-]cannot import in `data:` URL script[/-][+]cannot import built-ins in `data:` URL module[/+]aduh95 commentedon May 12, 2022
Not exactly related to your problem, but you should always encode the string you pass to be URL-friendly and avoid surprises, e.g. by passing
encodeURIComponent(scriptText))instead ofscriptText.This issue is a duplicate of #42860, it has been fixed #42881, it should be backported to v16.x in the next release.
nujarum commentedon May 12, 2022
@aduh95 Thanks for your reply. And sorry for the duplicate registration.
ChocolateLoverRaj commentedon Jul 27, 2022
@aduh95 I tried the same example with v16.16.0 and it still has the same error. Is it supposed to be fixed in v16.16.0 or some version >16.16.0?
aduh95 commentedon Jul 28, 2022
v16.16.0 doesn't have the fix (it was a security release, so it only includes the security fixes), so that's expected. It's supposed to be fixed in the next v16.x release though.