LeetCode-OpenSource / vscode-leetcode

Solve LeetCode problems in VS Code
https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-leetcode
MIT License
8.16k stars 646 forks source link

Circular Dependency #927

Open mahir-hs opened 6 months ago

mahir-hs commented 6 months ago

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).
woung717 commented 6 months ago

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.

ryderfang commented 6 months ago

Login issue is fixed by @woung717 's release, but got another issue:

Fetch solution failed.

image
woung717 commented 6 months ago

Login issue is fixed by @woung717 's release, but got another issue:

Fetch solution failed.

image

@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.

alexya commented 6 months ago

I met a similar issue

let s = args.map(x => x.toString()).join(' ');
                              ^
TypeError: Cannot read properties of undefined (reading 'toString')
ryderfang commented 6 months ago

@woung717 I used "leetcode.com", your latest release worked perfect! Great job, Thanks!

StevenJohnston commented 6 months ago

Not my brightest work but heres a fix. https://github.com/StevenJohnston/leetcode-cli

wallacezzzzz007 commented 6 months ago

@woung717 I tried your newest release, it works perfectly! thank you!

robpodosek commented 6 months ago

~@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.

jasoncyu commented 6 months ago

Not my brightest work but heres a fix. https://github.com/StevenJohnston/leetcode-cli

  • "Fixes" cookie login (You select cookie login but provide a cURL copied from your browser)
  • This is a patch for the underlying leetcode-cli package this extension uses. So you will need to tediously install my package in replacement of it. Sorry, I don't feel like forking this extension atm.
  • Does not fix OAuth login. Copied cURL for an OAuth login of course still works.
  • Does not fix leetcode.cn

very nice! Less changes needed than I thought. can confirm it works for me

robpodosek commented 6 months ago

@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.

- Sending code to judge
(node:43334) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
- Waiting for judge result
[ERROR] session expired, please login again [code=-1]

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.

woung717 commented 6 months ago

@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.

robpodosek commented 6 months ago

@woung717 agreed. Being logged into leetcode in the browser at the same time doesn't seem to have any effect on the extension. It was working for me this morning, then I went onto the next problem and now I'm back to 'undefined'. I bet if I try again in a few hours it'll suddenly magically work. Seems like a roll of the dice.

The cookie is working though because I can see my submission posted to leetcode although I'm getting an undefined response.

edit: yeah it started working again after a few hours

ghost commented 5 months ago

@woung717 How do we apply your fix? Do we simply over-write the files here?

Screenshot 2024-03-10 at 13 26 54

For reference this directory is in: /Users/current_user/.vscode/extensions/leetcode.vscode-leetcode-0.18.1

@codevisualisations See this. https://superuser.com/questions/73675/how-do-i-install-a-vsix-file-in-visual-studio

@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

MakiseJ commented 5 months ago

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. image 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.

tamy-le commented 5 months ago

I'm following this and it worked, detail steps :(:

https://github.com/skygragon/leetcode-cli/issues/194#issuecomment-559839631

  1. Right mouse click on leetcode page (please sign in first so it can give you session cookie) -> inpsect -> network -> reload -> any graphQL: Screenshot 2024-04-02 at 01 02 06
  2. Copy correct value corresponding to correct field to json file ~/.lc/leetcode/user.json (may create by self) Content in user.json should be like this:
    {
    "login": "[username]",
    "loginCSRF": "",
    "sessionCSRF": "[copied from csrftoken]",
    "sessionId": "[copied from LEETCODE_SESSION]"
    }

    then just open vscode and use extension normally - may need 1~2 seconds to sign in