vscode-javascript-repl-docs
vscode-javascript-repl-docs copied to clipboard
The URL class anywhere in the input breaks execution
Example of breaking code:
const d = new Date() //=
const url = new URL('https://www.my.example.com:8080/app/name'); //=
If you remove the line with url
, the d
value will recalculate and show and update on every change.
If you restore the url
line, updates stop. The url
value is never shown neither in the //=
, nor in the Logs Explorer.
Here the code uses WHATWG URL object, which is a recommended way.
The code will work if it uses a Legacy URL API (deprecated):
const url = require('url');
const app = url.parse('https://www.my.example.com:8080/app/name') //=
Hey, @a-bronx thank you so much for your feedback and I am sorry that you had this issue.
Basically, the repl is using by default a runtime context that is created on the same process. I chose to have this by default because this is "lighter" compared to use a separate process but it has some issues when users are running-testing code through repl specifically for node.js
(like this one) or they include some node modules that have support only for node.js' runtime.
In this context, some global node properties are not supported like URL
or URLSearchParams
. I think that I can support both of them. So until the next version, you can use 'Node' instead of the default 'VM' on the "JavaScript-repl: Context" option in vscode preferences-settings.
I have tested your example by using the Node
option and it works properly (please reload the vscode's window, in order to be sure that the new option has been applied).
Thanks again for your feedback and feel free to post again if you have any issues or questions.
@a-bronx I had some free time today so I took a look at this and it was simple to provide a solution for URL
and URLSearchParams
. So I have published a new version (0.6.9) that provides a fix about it.
I have tested your example and it works without the need to change the configuration "JavaScript-repl: Context" to Node
but as I wrote above in general this option is really helpful if users have issues with the default option.
Hi! I can confirm it now works on the sample provided. But the following one still fails, with or without "Node" param:
const url = new URL("./some/relative/path", import.meta.url)