17

I see this error in the Terminal while building a Rust application (which happens to be about NEAR Protocol, if you're curious):

error[E0463]: can't find crate for core

note: the "wasm32-unknown-unknown" target may not be installed

How can I fix it so that Rust will actually build my NEAR app?

user3840170
  • 26,597
  • 4
  • 30
  • 62
Dorian Crutcher
  • 381
  • 2
  • 7
  • 2
    Hi. It looks like you are trying to create a question and answered type of question. While these are acceptable on SO you should follow the correct format. Please put the question in the actual question and make sure it's detailed and then put your answer as an answer to the question. When creating you should notice there is an option to post a question with an answer at the bottom of the editor. Please see: https://stackoverflow.com/help/self-answer – The Grand J Feb 18 '21 at 01:46
  • i was having issues with trunk and fixed for me - thank you – SwiftD Feb 19 '21 at 15:20
  • 1
    I’m voting to close this question because it does not contain a question. – trent Feb 26 '21 at 17:54
  • Also voting to close for the same reason as @trentcl Turn this into a question and self-answer if you want to blog. – Evan Carroll Jun 25 '21 at 16:30
  • 1
    I get this exact error. When I run the rustup command, I still get the exact same error. What's going on here? – pfincent Jan 01 '22 at 21:57

6 Answers6

9

To solve this error, run:

rustup target add wasm32-unknown-unknown

in the terminal, and that should correct the issue.

Note: I'm simply posting here as an answer what the original question asker Dorian Crutcher already wrote within their question. But that suggestion did work for me too.

Ryan
  • 22,332
  • 31
  • 176
  • 357
6

For future readers (mostly myself) who run into this issue, there's another important factor that could be causing this error or similar errors which is extremely hard to realize: conflicting versions of Rust and/or Cargo. This means it persists even after running rustup target add wasm32-unknown-unknown.

In my case, I had rust installed from brew and rustup at the same time, which was causing a bunch of confusion and clashes. You should make sure you have Rust installed exclusively from rustup. Double check every package manager you have on your system, because rust may have been installed as a dependency of another package, such as through cargo-nextest in my case. Such packages should be uninstalled and managed instead through cargo itself, and thus kept under the purview of rustup.

naiveai
  • 590
  • 2
  • 14
  • 42
1

I had the same problem, its reason is in an out-of-date version of Rust, the solution was to update the Rust to the latest version.

ilyar
  • 1,331
  • 12
  • 21
  • This must not be true. For example, I *just* installed Rust for the first time and ran into this problem. `rustc --version` shows `rustc 1.58.1 (db9d1b20b 2022-01-20)`. And I checked https://github.com/rust-lang/rust/blob/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093/RELEASES.md which also says 1.58.1 (2022-01-19), so I definitely have the latest version of Rust. – Ryan Jan 27 '22 at 16:08
  • I don't yet understand https://stackoverflow.com/a/67928180/470749 but will look into that. – Ryan Jan 27 '22 at 16:09
1

I got a similar error while trying to install universal builds of py38-cryptography via Macports on Mac OS 12.1 with an M1 Max chip.:

:info:build error[E0463]: can't find crate for `core`
:info:build   |
:info:build   = note: the `x86_64-apple-darwin` target may not be installed

Rebuilding Macports' installed version of rust as universal works:

sudo port install rust +universal
tehfink
  • 447
  • 8
  • 7
0

I also ran into this problem for a different reason. I had explicitly specified the version of nightly compiler to rustup as version nightly-YYYY-MM-DD, but inside a toolchain file, I only specified nightly which I suspect refers to the latest nightly for which core, among many other things, was indeed not installed.

mallwright
  • 1,670
  • 14
  • 31
-2

May be somebody will help, ubuntu 20.04, just randomly found solution of next error:

error[E0463]: can't find crate for core

Run in terminal, rustup target add wasm32-unknown-unknown

user3840170
  • 26,597
  • 4
  • 30
  • 62
matthew5
  • 56
  • 8