Nix build of vuepress project is slow or hangs

I’m trying to package a vuepress project. I’ve successfully packaged other web projects before. But with vuepress, though I don’t get any errors the build is extremely slow or hangs (not finished within 20 mins through nix build even though a manual npm run docs:build takes less than 10 secs).

I have been unable to look into the process to figure out what’s happening. Either that’s not possible, or I lack knowledge of adequate tools.

I created an MWE and would be super glad if somebody could help me out!

Update: I suspected this was related in some way to sandboxing. It seems it’s not. Even nix build --no-sandbox does not succeed

I’ve been having issues with vitepress too, I wonder if you found any solutions.

Same symptoms as you: npm run docs:build works fine, but when you put it in a derivation, it hangs indefinetly.

No, I’ve not investigated further, unfortunately. Let me know if you find something, though

1 Like

@mvb It seems that redirecting stderr and stdout to /dev/null seems to solve my issue with vitepress. Maybe it’s the same with vuepress.

After looking at the strace -f output, the process was sending control codes to the terminal, and it may get confused when running under the daemon.

buildNpmPackage {
  # ....
  buildPhase = ''
    npm run build > /dev/null 2>&1
  '';

Great that you figured it out for your usecase! Unfortunately, when I try this, it does not hang, but errors. I’m able to inspect the error by redirecting it to a tmp file instead and using

nix build --keep-failed
ls -d /tmp/nix-build-* | tail -n 1

# cd into build directory and read `tmp` file

It is

> nixxer-docs@0.0.1 docs:build
> vuepress-vite build src

- Initializing and preparing data
✔ Initializing and preparing data - done in 4.75s
- Compiling with vite
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: spawn /build/docs/node_modules/sass-embedded-linux-x64/dart-sass/src/dart ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /build/docs/node_modules/sass-embedded-linux-x64/dart-sass/src/dart',
  path: '/build/docs/node_modules/sass-embedded-linux-x64/dart-sass/src/dart',
  spawnargs: [
    '/build/docs/node_modules/sass-embedded-linux-x64/dart-sass/src/sass.snapshot',
    '--embedded'
  ]
}

Node.js v20.17.0

I can’t say I really understand it.

However, this lead me to discover this issue in the sass-embedded project, which explains the problem a bit and suggests some solutions (which either are unreliable or didn’t work for me).

However, that issue suggests that it is a simple nixos-and-pre-built-binaries thing. However, if it was, I don’t see how it’s possible that build works outside of a nix build using npm run docs:build. Very curious