Problem compiling Anki natively on Windows

Previously, I compiled Anki in WSL. Compilation in WSL was easy but I wanted to compile Anki natively on Windows.

I installed Rust, Visual Studio and MSYS2, as mentioned in anki/docs/windows.md at main · ankitects/anki · GitHub.

Now, when I run bash tools/install-n2 in cmd.exe, I get the error:

tools/install-n2: line 3: cargo: command not found

But, running cargo --version in cmd.exe gives:

cargo 1.89.0 (c24e10642 2025-06-23)

which cargo in cmd.exe gives:

/c/Users/User/.cargo/bin/cargo

How can I fix this? Thanks in advance for any suggestions.

I figured out the cause.

The command was being run with WSL’s bash (installed at C:\Windows\System32\bash.exe) rather than MSYS’s bash. Both were in path, but since System32 is earlier in PATH, WSL’s bash wins.

I fixed the issue by running C:\msys64\usr\bin\bash.exe tools/install-n2 instead.

1 Like

The node_modules step on running .\run seems to be taking a lot of time, much more than I am used to seeing in WSL on the same computer. It hasn’t completed yet.

    Finished `release` profile [optimized] target(s) in 1.19s
[===============-                        ] 25/66 done, 1/1 running
node_modules (2231s)
  ? Do you want to continue? [Y/n]

Pressing y doesn’t do anything.

That’s weird. It definitely shouldn’t take this much time normally. Have you tried deleting node_modules and trying again?

Yes, I tried that and this output is from the second run.

Still running:

    Finished `release` profile [optimized] target(s) in 1.19s
[===============-                        ] 25/66 done, 1/1 running
node_modules (2709s)
  ? Do you want to continue? [Y/n]

Any difference if you run ./yarn install directly?

1 Like
.\yarn install

C:\Users\User\GitHub\anki>call .\out\extracted\node\yarn install
! Corepack is about to download https://repo.yarnpkg.com/4.6.0/packages/yarnpkg-cli/bin/yarn.js
? Do you want to continue? [Y/n] y

➤ YN0065: Yarn will periodically gather anonymous telemetry: https://yarnpkg.com/advanced/telemetry
➤ YN0065: Run yarn config set --home enableTelemetry 0 to disable

➤ YN0000: · Yarn 4.6.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 0s 268ms
➤ YN0000: ┌ Post-resolution validation
➤ YN0002: │ anki@workspace:. doesn't provide sass-embedded (p85ef9), requested by esbuild-sass-plugin and other dependencies.
➤ YN0086: │ Some peer dependencies are incorrectly met by your project; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code.
➤ YN0086: │ Some peer dependencies are incorrectly met by dependencies; run yarn explain peer-requirements for details.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 649 packages were added to the project (+ 523.98 MiB).
➤ YN0000: └ Completed in 45s 974ms
➤ YN0000: ┌ Link step
➤ YN0004: │ dprint@npm:0.47.4 lists build scripts, but all build scripts have been disabled.
➤ YN0004: │ esbuild@npm:0.25.3 lists build scripts, but all build scripts have been disabled.
➤ YN0004: │ esbuild@npm:0.25.5 lists build scripts, but all build scripts have been disabled.
➤ YN0004: │ svelte-preprocess@npm:6.0.3 [f4825] lists build scripts, but all build scripts have been disabled.
➤ YN0000: └ Completed in 55s 479ms
➤ YN0000: · Done with warnings in 1m 42s

After this, .\run finished the rest of the tasks in 102 seconds.

    Finished `release` profile [optimized] target(s) in 0.68s
n2: ran 41 tasks, now up to date

Build succeeded in 102.09s.

I think that yarn was just indefinitely waiting for approval here:

! Corepack is about to download https://repo.yarnpkg.com/4.6.0/packages/yarnpkg-cli/bin/yarn.js
? Do you want to continue? [Y/n] y
1 Like

But, this is still a bug in the build script that needs to be fixed. As I said above, pressing y when the message was shown on running .\run didn’t do anything.

I’ve never seen reports of this before or run into it, so it’s hard to debug. Does setting the COREPACK_ENABLE_DOWNLOAD_PROMPT=0 env var before building help? GitHub - nodejs/corepack: Package manager version manager for Node.js projects

To trigger the issue again, I need to go back to the state before .\yarn install. How to do that without removing the compiled rust packages?

I tried rm -rf node_modules and rm -rf out\node_modules. I confirmed that the directories were cleared and then ran .\run again. This time the issue didn’t occur, presumably because the state before .\yarn install wasn’t exactly restored.

I tried .\yarn uninstall too but that returned Couldn't find a script named "uninstall".

Try also deleting out/extracted. If that didn’t work, I’d remove the whole out folder (maybe except out/rust).

I couldn’t trigger it after running rm -rf out and rm -rf ts\.svelte-kit and even after deleting the whole anki folder. So, I think that yarn saved the approval somewhere system-wide.

Maybe the next person who hits this issue should try setting the COREPACK_ENABLE_DOWNLOAD_PROMPT=0 env var to see if it helps?

Yes, let’s suggest that. If it proves to work, we can make Anki set it.