Skip to content

Anchor Build Fails: proc-macro2 v1.0.95 Compilation Error with Missing Span Methods #60

@TheLazySol

Description

@TheLazySol

Issue:

I just recently decided to utilize some of the Solana Templates for the first time and during the anchor build, the compilation fails with errors related to missing methods in proc-macro2 v1.0.95.

It appears to be a dependency resolution issue where the version of proc-macro2 being pulled in (1.0.95) is incompatible with the version expected by Anchor's macros... though im not sure.

Error Messages

error[E0599]: no method named `file` found for reference `&proc_macro::Span`
error[E0599]: no method named `local_file` found for reference `&proc_macro::Span`

Image

Environment

  • Anchor version: 0.31.1
  • Solana CLI: 2.1.21 (src:8a085eeb; feat:1416569292, client:Agave)
  • proc-macro2 version: 1.0.95
  • OS: Linux (WSL2)
  • Rust version: 1.87.0

More Details

The error occurs in the proc-macro2 crate's wrapper.rs file, specifically when trying to access file() and local_file() methods on proc_macro::Span. These methods appear to be either:

  1. Not available in the current version
  2. Behind a feature flag
  3. Incompatible with the current version of proc-macro2 being used

Steps to Reproduce

  1. Followed the README.md guide to create a new project: pnpm create solana-dapp@latest -t gh:solana-developers/solana-templates/templates/template-next-tailwind-basic
  2. Run pnpm install
  3. Run pnpm run setup
  4. Run pnpm run anchor-build
  5. Observe compilation errors related to proc-macro2

  • Is there a specific version of proc-macro2 that is known to work with the current Anchor version?
  • Are there any feature flags that need to be enabled/disabled to resolve this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions