Issues with running Haxe via npx (launch Node via VS Code)

Hey there :). I’m hardly leaving my Haxe-lab now-a-days, stuck on an early 4 version and too focused on my huge Haxe project to read the news. But I did update my NodeJS and this seems to have caused an update in how “npx haxe” runs. I think when running haxe via npx, a different, newer version of the compiler is used?

First, my --library flags in build.hxml stopped working. Ok, I changed to -lib and it worked.
But then this code doesn’t compile anymore:

		SetTimeout.call(() ->
		{
			bootstrap();
		}, _delayForDebugging ? 2000 : 2);

It complains at the (), saying 'Unexpected )

Just by trial & error & some hunches, I replaced → with => and I put a “none” argument in the parenthesis and it moved on, only to fail at:

app.get(‘/choice/:choiceID’, (req, res, next) => {

Where it says “unexpected ,”

This, I can’t get rid of (even after replacing → with =>

Weird thing is that my code STILL COMPILES using a different launch method, which uses npx task, which runs “haxe build.hxml”, which, I presume, uses my older Haxe compiler.

It only fails when launching via VS Code debug, whose terminal dies saying:

The terminal process “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command npx haxe build.hxml” terminated with exit code: 1.

Any ideas? :slight_smile:

You can try running npx haxe -version and haxe -version to see which versions are being used.

The -> syntax should be valid for haxe 4 and up: Local Functions - Haxe - The Cross-platform Toolkit

1 Like

It seems like you ended up with an older version of haxe compiler, like 3.4.7

1 Like

Thank you @tobil4sk , useful tip. Yeap, indeed, the versions are different.

Hey @kLabz :slight_smile: nice to see you around. Here’s to us lurkers busy in the labs :smiley:

And damn, you’re right, I’m on 3.4.7. How do I update the haxe version used by npx? I just updated node and then when I first ran the project, it asked me to install something and I just said “yes” without thinking much about the version.

I think in package.json, you need to specify the Haxe version by adding a “haxeDependencies” section:

  "haxeDependencies": {
    "haxe": "4.2.5"
  },
1 Like

Nope… that didn’t seem to do anything :frowning:

I still get 3.4.7 when I do npx haxe -version. I tried an npm install -g haxe , hoping that this will somehow update whatever npx is using. Still stuck on 3.4.7. How in the world does one update npx haxe?

I think it’s worth drawing attention to this, haxe working well on npm would make a big difference to adoption I believe

I think we can get it as simple as npm install haxe 4.2.5. We’d need to provide precompiled binaries for individual which is common practise for many non-js tools, for example we can take inspiration from esbuild here. The current haxe package on npm is itself a mini package manager which downloads those precompiled binaries anyway; might as well give that job to npm

Installing haxe through npm and consistently building with the same version is exactly what lix does for you. The setup is quite easy: GitHub - lix-pm/lix.client: A dependable package manager for your Haxe projects

3 Likes

I don’t know what’s going on with my setup. I tried npm install haxe and despite having 5.2.1 in my package.json it installs this ancient 3.4.7 Haxe. So what I did was just to grab my own haxe executable that I had in a separate location, throw it in node_modules and that was that. It works now. Hack, ugly, don’t get it, but I don’t have the time to either :smiley:

*puts back his lab coat and goes back inside the quantum resonance chamber *

Okay, I just gave it a try with a new project, and here are the steps that I followed to use Haxe 4.2.5 installed from npm:

  1. Run npm init -y to create package.json
  2. Open package.json in an editor and add the haxeDependencies section that I mentioned in my previous reply.
  3. Run npm install --save-dev haxe
  4. Run npx haxe -version

It prints 4.2.5 to the terminal.

I made sure to install a different version of Haxe globally to rule out that npx haxe wasn’t using the global version. It’s definitely using the local version that I just installed with npm.

I think when you add a new haxeDependencies section to your existing project, you specifically need to install Haxe from npm again, or it’ll just keep using the version you had installed previously.

2 Likes