Skip to content
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 can't find files #223

Open
infu opened this issue Jul 5, 2023 · 15 comments
Open

Import can't find files #223

infu opened this issue Jul 5, 2023 · 15 comments

Comments

@infu
Copy link

infu commented Jul 5, 2023

Sometimes Motoko language server works and finds its files, sometimes it doesn't. Reloading doesn't help. Everything seems to be set properly, mops & dfx.json. Can't even find a local file. The only difference I can see is my git root is not where dfx.json is. Perhaps that path is being used? How the language server detects its dfx.json ?
image

@rvanasa
Copy link
Contributor

rvanasa commented Jul 5, 2023

Thanks for the bug report; I'll see if I can reproduce this on my end.

Everything seems alright for a simplified example, so would you be able to send a screenshot of your file / directory structure?

Also, does anything seem unusual in the extension log ("Output" -> "Motoko Language Server")?

The language server is able to handle multiple dfx.json files at a time in any subdirectory, so this is supposed to work even with a different Git root.

@infu
Copy link
Author

infu commented Jul 6, 2023

Thanks for pointing out where I should be looking.
image
It seems it doesn't like the simlinks my npm setup has and ends in infinite loop. I can fix that on my end.

Edit: Removing looping npm packages fixed it

@rvanasa
Copy link
Contributor

rvanasa commented Jul 6, 2023

Just to confirm, did this fix the original issue ("sometimes Motoko language server works and finds its files, sometimes it doesn't")?

I'll look into fixing this infinite loop condition to minimize the chance of the same situation happening in the future.

@infu
Copy link
Author

infu commented Jul 10, 2023

It works most of the time. (On Mac/Intel)
However, sometimes I get these errors. (not too often)
reloading VScode or Motoko language server thru palette doesn't help.
I have to close VScode and start it again. Then it works.
image

@rvanasa
Copy link
Contributor

rvanasa commented Jul 10, 2023

That is quite strange. What operating system are you using?

This might have something to do with VS Code itself rather than the extension, since the error messages indicate that the system path doesn't include npx or mops while the extension is being initialized.

@infu
Copy link
Author

infu commented Jul 11, 2023

MacOs 13.4

@rvanasa
Copy link
Contributor

rvanasa commented Jul 11, 2023

Thanks! I'll let you know if I find a way to reproduce this issue on my end (also on macOS 13.4).

You could try running mops sources and npx ic-mops sources in a terminal to see if anything unexpected happens (and then running code . from the same terminal to inherit the system path). If this doesn't help, then it might be worth reinstalling VS Code and perhaps running the Motoko extension by itself to try and narrow down the root cause.

@rvanasa
Copy link
Contributor

rvanasa commented Aug 22, 2023

Hi @infu, are you still running into this issue? Here are a few more debugging steps that might help narrow down what's happening:

  • What happens if you remove or change defaults.build.packtool in your dfx.json file?
  • Do you get a "command not found" message when running which npx and which mops in the VS Code dev console?

@ottodevs
Copy link

same issue here

@infu
Copy link
Author

infu commented Sep 1, 2024

Haven't seen the 'looping' errors, but I stumble on other errors all the time on all my PCs, different OSes. Different errors. Sometimes they fix after window reload or language server restart.

Like this - Worked until I restarted VScode (no errors in log, files are there, paths are correct):
image
Most of my repos are pretty simple
image
In this case trying to import local libraries.
Somehow after adding the library directories to the vscode workspace, it started working again. Perhaps VScode doesn't allow the extension to touch files unless in workspace? Just checked that out and it seems to be true. Removing library folder brings the error back.

@rvanasa
Copy link
Contributor

rvanasa commented Sep 4, 2024

Thanks for the details and screenshots!

Perhaps VScode doesn't allow the extension to touch files unless in workspace?

This is correct. We have a workaround in the backlog. For the time being, it's necessary for all the Motoko files to be contained in the VS Code workspace.

@infu
Copy link
Author

infu commented Sep 27, 2024

I was still getting errors. Mops not found. Then npx not found. Tried removing nvm and installing node with apt, but it didn't fix it. I am having that problem on MacOS and also on Ubuntu. And it only bugs sometimes.
So I'll just go with this:
image

mops sources > mops.sources

@infu
Copy link
Author

infu commented Sep 27, 2024

Actually, removing defaults.build.packtool worked. I guess you are doing it internally in a different way

@rvanasa
Copy link
Contributor

rvanasa commented Sep 27, 2024

Glad you found a workaround! I've also experienced what you're describing but haven't yet been able to reliably reproduce the issue. This is most likely related to how VS Code passes environment variables to extensions, especially if npx is on your system path.

@infu
Copy link
Author

infu commented Sep 28, 2024

I'll have to go back to packtool: "cat mops.sources"
When packtool is removed from dfx.json then dfx build command doesn't work, while the VSCode extension works.
@ZenVoich perhaps mops install and add, when called can just write a file (with mops sources contents) in .mops dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants