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

Getting started guide doesn't mention npm installation, which results in Error: No such file or directory (os error 2) when running "anchor init" #3281

Open
shawazi opened this issue Sep 25, 2024 · 4 comments
Labels

Comments

@shawazi
Copy link
Contributor

shawazi commented Sep 25, 2024

Problem:

anchor init anchor-counter --template multiple has an OS error on Arch Linux.
However, the project is created despite the error. The error occurs every time the command is run.

The solutions at https://solana.stackexchange.com/questions/1648/error-no-such-file-or-directory-os-error-2-error-from-anchor-test don't seem to solve the underlying issue - upon running the anchor init command for multiple files template, a developer shouldn't see an OS error. If it's occurring due to Anchor being unable to generate an IDL from the template, then the template should possibly include the boilerplate necessary to generate a basic IDL.

 ╭─dev@dev in ~/Code took 4ms
[🔴] × node --version
v22.9.0

 ╭─dev@dev in ~/Code took 6ms
 ╰─λ yarn --version
1.22.22

 ╭─dev@dev in ~/Code took 173ms
 ╰─λ solana --version
solana-cli 1.18.18 (src:83047136; feat:4215500110, client:SolanaLabs)

 ╭─dev@dev in ~/Code took 3ms
 ╰─λ avm --version
avm 0.30.1

 ╭─dev@dev in ~/Code took 22ms
 ╰─λ anchor --version
anchor-cli 0.30.1

 ╭─dev@dev in ~/Code took 3ms
[🔴] × anchor init anchor-counter --template multiple

Error: No such file or directory (os error 2)

 ╭─dev@dev in ~/Code took 4ms
[🔴] × ls
drwxr-xr-x - dev 25 Sep 19:31  anchor-counter

 ╭─dev@dev in ~/Code/anchor-counter via  v1.81.0 as 🧙 took 8s
[🔍] × tree
.
├── Anchor.toml
├── app
├── Cargo.toml
├── migrations
├── programs
│   └── anchor-counter
│       ├── Cargo.toml
│       ├── src
│       │   ├── constants.rs
│       │   ├── error.rs
│       │   ├── instructions
│       │   │   ├── initialize.rs
│       │   │   └── mod.rs
│       │   ├── lib.rs
│       │   └── state
│       │       └── mod.rs
│       └── Xargo.toml
└── target
    └── deploy
        └── anchor_counter-keypair.json

10 directories, 11 files

Solution:

Add the boilerplate code to the dummy files that are causing the OS error on anchor init anchor-counter --template multiple

@acheroncrypto acheroncrypto added bug Something isn't working cli labels Sep 26, 2024
@acheroncrypto
Copy link
Collaborator

I'm not able to reproduce the problem unfortunately. Does it only happen if you use the multiple template?

The solutions at https://solana.stackexchange.com/questions/1648/error-no-such-file-or-directory-os-error-2-error-from-anchor-test don't seem to solve the underlying issue

The Error: No such file or directory (os error 2) error is a generic file system error, so it's difficult to pinpoint where exactly it's coming from. Searching the web for this error is unlikely to yield good results because of this reason.

If it's occurring due to Anchor being unable to generate an IDL from the template, then the template should possibly include the boilerplate necessary to generate a basic IDL.

The post is from 2 years ago when Anchor had a different way of generating the IDLs. It's also running the anchor test command, so this problem is unrelated (other than the error itself).

This would be easy to debug if I could reproduce.

@shawazi
Copy link
Contributor Author

shawazi commented Sep 26, 2024

Hey, thanks for the response! I realized why it occurred. I didn't have npm installed.

https://www.anchor-lang.com/docs/installation I was following this guide on a fresh system (i believe garuda (arch) with fish, but maybe bash).

I installed node directly, I believe, rather than via nvm. I think nvm may provide node and npm, possibly, and perhaps that's why the anchor-lang installation guide doesn't mention it.

It might be beneficial to add a section in the installation guide for "node" and "npm" (or "nvm" if that has both node and npm), alongside the checks for Rust and Yarn.

@acheroncrypto
Copy link
Collaborator

It might be beneficial to add a section in the installation guide for "node" and "npm" (or "nvm" if that has both node and npm), alongside the checks for Rust and Yarn.

Possibly, but I'd prefer to handle this error in the CLI itself (provide a good error message) because the installation guide has been getting longer lately, which could be scary for new people.

Since this problem is unrelated to the multiple files template, it would be great if we could either close this issue, or rename it to something that includes npm.

@acheroncrypto acheroncrypto removed the bug Something isn't working label Sep 26, 2024
@shawazi shawazi changed the title multiple files template: Error: No such file or directory (os error 2) Getting started guide doesn't mention npm installation, which results in Error: No such file or directory (os error 2) when running "anchor init" Sep 26, 2024
@shawazi
Copy link
Contributor Author

shawazi commented Sep 26, 2024

I see your point, but as a new person following the official documentation, I hit a 30 minute roadblock that hindered additional javascript testing since anchor didn't create the tests directory or package.json, or tell me exactly what went wrong.

It might save a lot of time collectively if the documentation contains the two additional lines to check that the new anchor user has node and npm installed on their system, such as via:

### Node and NPM
Install them both onto your system by following this guide: https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/

I really think a new person would prefer to have the proper dependencies listed in the getting started guide, rather than playing guessing games with the ambiguous CLI error message. And if the documentation is comprehensive, then there's no mental discrepancy (the documentation for installation doesn't mention node or npm, but the cli error message does? why?)

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

No branches or pull requests

2 participants