nexe/nexe

I got `Error: spawn EINVAL` error, after change host's node version `21.7.2` to `21.7.3` or `20.12.1` to `20.12.2` on Windows.

mikoto2000 opened this issue · 9 comments

What happened:

I got Error: spawn EINVAL error, after change host's node version 21.7.2 to 21.7.3 or 20.12.1 to 20.12.2. on Windows.

maybe related CVE-2024-27980.

See: https://nodejs.org/en/blog/release/v21.7.3

nexe/src/compiler.ts

Lines 209 to 213 in 175bbf1

spawn(command, args, {
cwd: this.src,
env: this.env,
stdio: this.log.verbose ? 'inherit' : 'ignore',
})

nexe version nexe 5.0.0-beta.1 and node version 20.12.2

PS C:\devcontainers-cli> nexe -i ./devcontainer.js -t windows-x64-20.12.2 -b -o /dist/devcontainer-windows-x64-20.12.2-nexe.exe
i nexe 5.0.0-beta.1
√ Including dependency: C:\devcontainers-cli\dist\spec-node\devContainersSpecCLI.js
√ Node source extracted to: C:\Users\ContainerAdministrator\.nexe\20.12.2
√ Compiling Node with arguments: nosign,release,x64
√ Finished in 114.143s
Error: spawn EINVAL
    at ChildProcess.spawn (node:internal/child_process:421:11)
    at spawn (node:child_process:761:9)
    at C:\nexe\lib\compiler.js:163:39
    at new Promise (<anonymous>)
    at NexeCompiler._runBuildCommandAsync (C:\nexe\lib\compiler.js:162:16)
    at NexeCompiler.<anonymous> (C:\nexe\lib\compiler.js:201:24)
    at Generator.next (<anonymous>)
    at fulfilled (C:\nexe\lib\compiler.js:11:58)

What you expected to happen:

Build success.

How to reproduce it (as minimally and precisely as possible):

  1. remove node prebuild binary
  2. build example/express-app
    • ex: nexe -i ./index.js -t windows-x64-20.12.1 -b -o ./dist/express-app-windows-x64-20.12.1-nexe.exe

Anything else we need to know?:

Environment:

  • Platform(OS/Version): Windows Server 2022(Docker Image: mcr.microsoft.com/windows/servercore:ltsc2022)
  • Host Node Version: 21.7.3, 20.12.2, 18.20.2
  • Target Node Version: any
  • Nexe version: v5.0.0-beta.1, v4.0.0-rc.4
  • Python Version: 3.12

i have the same error.

node version: v20.12.2
nexe version: 4.0.0-rc.4
(windows x64) .
tried to run this command:
nexe start.js -r "config.js" -r "nexe.config.js" -r "routes/common/oauth.js" -r "routes" -r "public//." -r ".vscode/**/." -r "package-lock.json" -r "package.json" --build --node --output "BI-Fitouts-local.exe"

this is the log and error:

PS C:\Users\Or-Admin\OneDrive - Tidhar Construction\BIM\Forge\BI_Fitouts> nexe start.js -r "config.js" -r "nexe.config.js" -r "routes/common/oauth.js" -r "routes" -r "public//." -r ".vscode/**/." -r "package-lock.json" -r "package.json" --build --node --output "BI-Fitouts-local.exe"

i nexe 4.0.0-rc.4
√ Included 42 file(s)
√ Already downloaded...
√ Compiling Node with arguments: nosign,release,x64
√ Finished in 1.32s
Error: spawn EINVAL
at ChildProcess.spawn (node:internal/child_process:421:11)
at spawn (node:child_process:761:9)
at C:\Users\Or-Admin\AppData\Roaming\npm\node_modules\nexe\lib\compiler.js:162:39
at new Promise ()
at NexeCompiler._runBuildCommandAsync (C:\Users\Or-Admin\AppData\Roaming\npm\node_modules\nexe\lib\compiler.js:161:16)
at NexeCompiler. (C:\Users\Or-Admin\AppData\Roaming\npm\node_modules\nexe\lib\compiler.js:200:24)
at Generator.next ()
at fulfilled (C:\Users\Or-Admin\AppData\Roaming\npm\node_modules\nexe\lib\compiler.js:11:58)

How to fix locally until fix is merged with source

Download the source code
git clone https://github.com/nexe/nexe.git

open cmd window at source code root
npm install

Open nexe\src\compiler.ts with notepad++ (different from windows notepad! goggle it)

Go to line 211 env: this.env,
Below this line add
shell: true,

Save

In cmd (at same location as nexe source root)
npm link

cd to the directory of your project you want to use nexe

npm link nexe

now run your command to use nexe

eg
nexe -i myfile.js -o nameofexe -t windows --build --verbose

Thanks to mikoto2000 for the fix
Pull request with fix #1092

Tested on node version 21.7.3

thanks for the explenation.
i tried this, and indeed the EINVAL error did not apear. i got another error
(ran this command)
nexe start.js -r "config.js" -r "nexe.config.js" -r "routes/common/oauth.js" -r "routes" -r "public//." -r ".vscode/**/." -r "package-lock.json" -r "package.json" --build --output "myApp.exe"

and got error :

Debugger attached.
i nexe 5.0.0-beta.1
√ Included 42 file(s)
√ Including dependency: C:\Users\Or-Admin\OneDrive - Tidhar\BIM\Forge\webApps\BI_Fitouts\node_modules\dotenv\package.json
√ Already downloaded...
√ Compiling Node with arguments: nosign,release,x64
√ Finished in 83.944s

Error: vcbuild.bat nosign release x64 exited with code: 1

** using node v20.12.2
**tried to download nasam ( as suggested here: #799 ) --> still did not work

thanks for the explenation. i tried this, and indeed the EINVAL error did not apear. i got another error (ran this command) nexe start.js -r "config.js" -r "nexe.config.js" -r "routes/common/oauth.js" -r "routes" -r "public//." -r ".vscode/**/." -r "package-lock.json" -r "package.json" --build --output "myApp.exe"

and got error :

Debugger attached. i nexe 5.0.0-beta.1 √ Included 42 file(s) √ Including dependency: C:\Users\Or-Admin\OneDrive - Tidhar\BIM\Forge\webApps\BI_Fitouts\node_modules\dotenv\package.json √ Already downloaded... √ Compiling Node with arguments: nosign,release,x64 √ Finished in 83.944s

Error: vcbuild.bat nosign release x64 exited with code: 1

** using node v20.12.2 **tried to download nasam ( as suggested here: #799 ) --> still did not work

Make sure you have visual studio 2022 installed and the visual studio build tools

If you have both of these installed do a clean of nexe

enter your command you would use to run what you want to package but start it with nexe --clean (rest of your command)

then enter the command again without the --clean

I also have nasam added to path (windows environmental values) but I don't think this error relates to that

@purplescorpion1 thank you for your explenation!
it did not work at first (through the vs code's project terminal) , but then i restarted, and cd to the projects folder using the command line, and it finally worked,...

compiler.js
line 163 add:

            shell: true,

before

            cwd: this.src,

OMG I wish I would have come here first, I've spent all day trying to use nexe with node 18.20.2 and kept failing but it compiled fine with 18.15.0. As I was installing on my new work PC I was convinced I'd missed some prereq install, turned out the shell: true is all it needed for me.

Hi, thx for this hotfix.
We got the same error and adding shell: true, solved the issue.
In the moment, this bug blocks our build agent, which does a fresh npm ci on each run.

Hi, thx for this hotfix. We got the same error and adding shell: true, solved the issue. In the moment, this bug blocks our build agent, which does a fresh npm ci on each run.

All I can suggest is forking the repo into your own account. Apply the correction then have your build agent run it from your fork. You could always upload it to npm under a different name if you can't run it directly from GitHub. Not sure what the requirements are