vscode-leetcode: Circular Dependency
Can’t log in anymore. Gives this error,
(node:14912) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created).
About this issue
- Original URL
- State: open
- Created 4 months ago
- Reactions: 10
- Comments: 65
I fixed it to make it work. Leetcode changed all the endpoint requires x-csrftoken header. Thanks for the tips. @kawre
I compiled and uploaded full extension binary. You can download from here. You can load locally by VSCode -> Extensions Menu -> “…” icon -> Install from VSIX…
~You can test from below. https://github.com/woung717/vscode-leetcode/tree/leetcode-cli-change https://github.com/woung717/leetcode-cli/tree/fix-cloudflare-issue~
But the problem is that leetcode-cli, where I modified, is quite old and no longer seems to be maintained. (Last pull request merge was 2022) ~Maybe we should fork the branch from leetcode-tools / leetcode-cli and merge into it?~
@jdneo Can you check the pull request?
Same issue here 😦
I’m using the cookie login but it’s not working anymore.
Update:
Also It seems other folks are facing this issue as well, https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478#issuecomment-1983281960
Guys I reported the issue to Leetcode Support Team last week, and they replied that the problem was fixed today. I think all of us can go on with the extension successfully now. Translation: Thank you for your letter. We have promptly forwarded your feedback to our product and technical teams. The technical team has updated and fixed the issue with the VSCode plugin. We suggest you try again. We will continuously improve such features to provide users with a better learning experience. If you have more suggestions and feedback, please feel free to contact us.
Leetcode has updated their cloudflare to block requests without some http headers
For example I’ve modified
vsc-leetcode-cli
locally and changingplugin.makeOpts
function to include dummyUser-Agent
andHost
headers will make signing in work againIn my case, my plugin had to only include new dummy
User-Agent
header to start working again. https://github.com/kawre/leetcode.nvim/pull/70This is a bundle of headers that gets sent with every request made by my plugin and everything seems to be working fine
find the root cause 😃 , leetcode website update http proto to allow HTTP/2, letcode-cli request still send http/1.1 request.
So as @StevenJohnston @jasoncyu said, there are two issues we need to address.
The first is the HTTP header issue, which is about Leetcode changing their Cloudflare - HTTP header policy, and I fixed this in this branch by modifying some headers (thanks to @kawre).
Also, I changed the VSCode prompt login method to the browser method. This is not much related to the issue, but still the prompt ID/PW login method was not working so I fixed it too.
And the second, I suspect, is related to location and cloudflare/HTTP2, as not all users are experiencing the error after the first fix is applied. I can’t reproduce the bug, so I can’t fix and test it.
To solve this issues completely, I think someone needs to change the HTTP client on one of my branch to support HTTP2. (Or you can fix the HTTP headers on your branch first and then replace HTTP client.) But the problem is, most of the currently well-maintained CommonJS HTTP2-supporting libraries have different API to the current ‘request’ API. It may take some time to replace them, and worth noting that bugs are in leetcode-cli.
And again, I hope someone who own this project take care of this issue and see how we can patch it as this is the most popular leetcode extension in VSCode. Otherwise, we have to fork this project and maintain this and leetcode-cli both.
I changed the plugin to login using chrome browser.
You can login via id/pw, 3rd party (Github, Linkedin, etc…) at the browser. Select “LeetCode Account” among Sign In options. Cookie option is still available. It might take some time to download chrome browser at first time.
You can download plugin(.vsix) file here.
You can load locally by VSCode -> Extensions Menu -> “…” icon -> Install from VSIX…
maintainer has not been active, last commit was 2 years ago
I’m following this and it worked, detail steps 😦: #https://github.com/skygragon/leetcode-cli/issues/194#issuecomment-559839631
then just open vscode and use extension normally - may need 1~2 seconds to sign in
@woung717 can confirm the changes let me login and submit. thanks for your work.
Anyone else who wants to install woung’s patch just follow this guide https://www.youtube.com/watch?v=Z724l3mq2ag after downloading his latest release as a .vsix file: https://github.com/woung717/vscode-leetcode/releases
~@woung717 I’m using your latest 0.18.1. I’ve noticed I’m able to load and fetch all the problems, but when I submit a solution I get undefined in the submissions tab. However, when I sign into the problem on leetcode I can see that it actually successfully my solution. So the submission POST is working but it’s not properly receiving and/or parsing the response.~
Scratch that, it just started working and returning the Accepted submission result in the IDE. I didn’t change anything on my end, must have been a leetcode thing.
Not my brightest work but heres a fix. https://github.com/StevenJohnston/leetcode-cli
Holy crap this works! I loaded it from the vsix file and everything just loaded. I didn’t even have to sign in anywhere (maybe because I was already signed into leetcode). You’re a godsend thanks dude.
It seems I’m still facing the same problem using this extension, tried both browser and cookie.
Also note that headless browsers may have chances not passing Cloudflare Turnstile (see here), so I used a third-party login method here.
And Google also regards this browser as insecure, which may be a hint to the previous problem.
I tried log in with Github and cookies, both of them failed.
I can confirm this is working for me for both choosing problems and submitting them. Great work! It seems like there was no need to upgrade sending requests to http/2 after all, at least for our cases.
@robpodosek I forgot to say that it is not published in JetBrain Plugin Marketplace yet. You can download the updated version in the github repository. leetcode-editor-8.10.zip
@robpodosek I’ve only sent an example. Messing around with the headers I’ve sent I was able to login, open a question and run it.
The problem is that
leetcode-cli
logs you out if one of the requests return with status code of 403 or 401. To avoid this you would need to ensure that every request sent includes the headers I’ve mentioned or else you will get logged out if any request fails. But not every request is usingplugin.makeOpts
to create opts, so this not the only place it needs to be changed.This is because if you try to use third party login, it will send a verify code to your mailbox. That’s why it says password incorrect.
It’s cloudflare, i printed out the response that I’m getting on some of the API calls and it says this:
full html here: https://pastebin.com/cTTAf8cb
I got this a few months ago, I wasn’t able to figure out a solution, it just ended up going away after a while
@robpodosek From my experience, if you access leetcode on the browsers and do something on this extension at the same time, session can be expired. So I submit and see code only on the extension.
edit: I faced the same situation without any additional web browser session, and it occurred when I submitted code multiple times too quickly. I think it is a leetcode side problem. Maybe retry logic can be added but it would be not easy.
@woung717 Okay so the 0.18.1 patch wasn’t working (see my strikethrough’d comment above). Then it was working last night. Now it’s back to not working, it’s posting the code to leetcode when I check on the site, but in vscode it’s showing ‘undefined’ again and saying that my session is expired despite still posting the code to leetcode. I’m also still getting the padLevels error.
edit: aaaand now it’s working again and returning the result in VS Code. This seems to be an intermittent issue on the leetcode side.
very nice! Less changes needed than I thought. can confirm it works for me
@woung717 I tried your newest release, it works perfectly! thank you!
@woung717 I used “leetcode.com”, your latest release worked perfect! Great job, Thanks!
@ryderfang Thank you for the report. Which Release/Endpoint(leetcode.com or leetcode.cn) do you use?
Add: I forgot to update Fixed_Release’s dependencies. I updated and uploaded binary again. Check this if you have used Fixed_Release and leetcode.com endpoint.
@hakula139 As you see the web page, it is not a headless browser. It’s a just standalone Chrome browser but just controlled by automated program. (leetcode-cli in this case) And about the Turnstile fail, it display failure, however you can login if you click the “Sign In” button. I saw there are some kind of puppeteer plugin to make it stealth mode, but I couldn’t test since it works without the plugin. Anyway, thank you for your report. I’ll see it more.
For someone who have enough time, I think we need investigate can HTTP2 fix failures which some users have. Leet-cli still use ‘request’ http client to query after browser login proccess.
I think I can fix the ID/Password method too if it is okay to add selenium or puppeteer… Since browser dependency might cause compatibility issue, though.
For those who urgently need a leetcode IDE solution, this is an alternative. ~https://plugins.jetbrains.com/plugin/12132-leetcode-editor~ https://github.com/shuzijun/leetcode-editor/releases You can use the plugin with the free JetBrain IDEs. The plugin bypasses the CloudFlare problem with the in-IDE browser. By the way, I hope the issue is solved.
Edit: Changed a link. (Plugin MarketPlace -> Github Repository)
I added those lines to /Users/myuser/.nvm/versions/node/v18.18.2/lib/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js but it doesn’t seem to have any effect when I use the cookie login.
hmm I tried replacing the library with some ones that send http/2 requests, I’m still getting the same cloudflare 403 error page in response. Hopefully you get some better luck than me
Have you solved this problem
How long did it take to work again?