-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot import built-ins in data:
URL module
#43060
Comments
@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. const scriptText = `
export * from 'path'
export const foo = 'bar'
`
const { sep } = await import(`data:text/javascript,${scriptText}`)
console.log(sep) |
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 |
This may be a similar issue to #42890. |
since you corrected the original issue now it wasn't clear to what you were referring to. |
data:
URL scriptdata:
URL module
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 const scriptText = `
import path from 'path';
export const foo = 'bar';
`.trim();
await import(`data:text/javascript,${scriptText}`); // Wrong, only works by accident if the JS contains no URL special chars.
await import(`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. |
@aduh95 Thanks for your reply. And sorry for the duplicate registration. |
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. |
Version
v16.15.0
Platform
Microsoft Windows NT 10.0.19044.0 x64
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
According to the
data:
Imports section of the documentation, the following is mentioned:If this documentation is correct, I believe it should be able to import the builtin module
path
successfully in adata:
URL script.What do you see instead?
Additional information
In another Node.js version, the output is as follows:
The text was updated successfully, but these errors were encountered: