-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
import(data:text/javascript,) throw SyntaxError #42504
Comments
A simpler example is here: const c = "const a = '?' === false;";
import(`data:text/javascript,${c}`).then((res) => {
console.log(res);
}); |
Yep, it looks like Node.js is acting differently than other JS runtimes. //cc @nodejs/loaders FWIW, you can workaround this by encoding special URL characters: const c = "const a = '?' === false;";
import(`data:text/javascript,${encodeURIComponent(c)}`).then((res) => {
console.log(res);
}); |
Please encode special components and/or use base64 support in your This failure is caused by a disagreement on if query parameters are valid on |
Thanks, It works on node16, but still failed on node14, but with base64 format, both will work well, like this: const c = "const a = '?' === false;";
import(`data:text/javascript;base64,${Buffer.from(c).toString('base64')}`).then((res) => {
console.log(res);
}); |
I think the fix was already backported to v14.18.0 (98259dc). Are you testing on an up-to-date version? |
yes yes, 14.18.0 is ok,👍 (the error occurs on 14.17.1) |
The problem is solved, if there is no other questions, I will close this issue after a few days. Thank you very much. |
Always use |
Version
v16.14.2
Platform
Darwin tingyuandeMacBook-Pro.local 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
Just run the code with latest node, error is here:
but, in chrome, the code runs well, no error.
How often does it reproduce? Is there a required condition?
100% reproduce.
What is the expected behavior?
no error should be thrown, It seems related to
?
(ternary operator).What do you see instead?
node can not run the code, but chrome can run the same code.
Additional information
No response
The text was updated successfully, but these errors were encountered: