lydell/elm-watch

Getting the error `Error: spawn Unknown system error -8` when using Node 18

Opened this issue · 9 comments

It seems that with Node > 16 this error happens

Unexpected error:
Error: spawn Unknown system error -8
    at ChildProcess.spawn (node:internal/child_process:413:11)
    at spawn (node:child_process:757:9)
    at /Users/.../node_modules/elm-watch/index.js:3087:19
    at new Promise (<anonymous>)
    at promise (/Users/.../node_modules/elm-watch/index.js:3082:36)
    at spawn2 (/Users/.../node_modules/elm-watch/index.js:3158:99)
    at install (/Users/.../node_modules/elm-watch/index.js:3703:29)
    at continuation (/Users/.../node_modules/elm-watch/index.js:3818:33)
    at installDependencies (/Users/.../node_modules/elm-watch/index.js:3876:14)
    at /Users/.../node_modules/elm-watch/index.js:7333:35

Hi! I used elm-watch with Node.js 18 for a long time, and now I use Node.js 20 and it works fine. The tests also run Node.js 18.

Can you post more details?

I tried several Node versions and I got this weird pattern:

OK v16.14.2
Error v18.15.0
OK v18.16.0
Error v18.17.0
Error v18.17.1
Error v20.3.1
Error v20.7.0

On a MacBook Pro - Ventura 13.5.2

Huh, that’s strange.

Could you make a reproduction repo? Then I could clone it and play around as well, with the different Node.js versions you posted.

Do you mean a repo with Elm code? This is an example of a project that shows that error: https://github.com/lucamug/elm-web-components (you can run both elm-watch and a web server with cmd/start).

But other repos have the same issue, for me. So I think is not related to the specific project. Also it is not excluded that is a specific problem of my configuration

A “reproduction repo” usually means a minimal repo that you make just to demonstrate an issue. It should contain step-by-step instructions on which terminal commands to run to reproduce.

Ok, I found the issue.

My projects install Elm inside node_folder but I assume elm-watch use the global install.

For some reason, the global install did not work. Executing elm just did not return anything.

Reinstalling Elm globally with npm -g install @lydell/elm fixed the issue.

This was hard to find! I was able to notice something strange only after I tried to run "elm init" on some of the non-working Node versions.

I wonder if having elm-watch to point to a different binary could be useful.

I expect devs that clone my projects to run "npm install" without requiring them to install Elm manually.

elm-watch tries to spawn just elm:

command: "elm",

So it’s up to you to make sure that elm is in PATH. elm-test works that way too, and elm-review (unless I’m mistaken). The idea is that:

  • If you install elm-watch globally, why wouldn’t you install elm globally as well?
  • If you install elm-watch locally, you execute it with npx. npx adds local node_modules/ folders to PATH, so both locally installed elm and globally installed elm are found.

Either way, elm-watch should never exit with “Unexpected error:” – it should print a helpful message. I tried to reproduce myself now. I made sure that elm-watch in in PATH, but not elm. This is what I get when running elm-watch hot:

-- ELM NOT FOUND -------------------------
/Users/simon/stuff/elm.json

I tried to execute elm, but it does not appear to exist!

This is what the PATH environment variable looks like:

/Users/simon/.local/share/nvm/v20.5.0/bin
/Users/simon/.ghcup/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/share/dotnet

Is Elm installed?

Note: If you have installed Elm locally (for example using npm or elm-tooling),
execute elm-watch using npx to make elm-watch automatically pick up that local
installation: npx elm-watch

I wonder what happens in your case? Does child_process.spawn() throw an error for some reason? I didn’t know it could. 🤔

It is a weird case where the elm command works but nothing happens. This is what elm-review returns:

-- UNEXPECTED ERROR ------------------------------------------------------------

I ran into an unexpected error. Please open an issue at the following link:
  https://github.com/jfmengels/node-elm-review/issues/new

Please include this error message and as much detail as you can provide. If you
can, please provide a setup that makes it easy to reproduce the error. That will
make it much easier to fix the issue.

Below is the error that was encountered.
--------------------------------------------------------------------------------
undefined

and this is what elm-test returns:

Compiling
Error attempting to run Elm compiler "/usr/local/bin/elm":
Error: spawn Unknown system error -8

Strange indeed!

  • I wonder what “Unknown system error -8” means. Tried to Google it a little but nothing has come up so far.
  • elm-test says /usr/local/bin/elm.
    • What happens if you execute that directly?
    • What does file /usr/local/bin/elm say?
    • What does shasum -a 256 /usr/local/bin/elm say?
    • Where does that binary come from / how did you install it?