node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
599 stars 117 forks source link

NixOS: Receiving an error of command failed when attempting to utilize the plugin on a fresh install. #286

Open saurin-tech opened 11 months ago

saurin-tech commented 11 months ago

I'm attempting to use the plugin with gradle version of 7.6 but I'm running into the error shown below.

Task :b:npmInstall FAILED
npm ERR! code 127
npm ERR! path /home/dev/a/b/c/node_modules/@swc/core
npm ERR! command failed
npm ERR! command sh -c node postinstall.js
npm ERR! sh: line 1: /home/dev/a/b/c/.gradle/nodejs/node-v18.17.1-linux-x64/bin/node: cannot execute: required file not found

npm ERR! A complete log of this run can be found in: x.log

Contents of x.log file

verbose stack Error: command failed
1083 verbose stack     at ChildProcess.<anonymous> (/home/dev/a/b/c/.gradle/nodejs/node-v18.17.1-linux-x64/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27)
1083 verbose stack     at ChildProcess.emit (node:events:514:28)
1083 verbose stack     at maybeClose (node:internal/child_process:1091:16)
1083 verbose stack     at Socket.<anonymous> (node:internal/child_process:449:11)
1083 verbose stack     at Socket.emit (node:events:514:28)
1083 verbose stack     at Pipe.<anonymous> (node:net:323:12)
1084 verbose pkgid @swc/core@1.3.81
1085 verbose cwd /home/dev/a/b/c
1086 verbose Linux 6.1.49
1087 verbose node v18.17.1
1088 verbose npm  v9.6.7
1089 error code 127
1090 error path /home/dev/a/b/c/node_modules/@swc/core
1091 error command failed
1092 error command sh -c node postinstall.js
1093 error sh: line 1: /home/dev/a/b/c/.gradle/nodejs/node-v18.17.1-linux-x64/bin/node: cannot execute: required file not found
1094 verbose exit 127
1095 timing npm Completed in 11972ms
1096 verbose unfinished npm timer reify 1693431512159
1097 verbose unfinished npm timer reify:build 1693431523676
1098 verbose unfinished npm timer build 1693431523676
1099 verbose unfinished npm timer build:deps 1693431523676
1100 verbose unfinished npm timer build:run:postinstall 1693431523683
1101 verbose unfinished npm timer build:run:postinstall:node_modules/@swc/core 1693431523683
1102 verbose unfinished npm timer build:run:postinstall:node_modules/esbuild 1693431523711
1103 verbose code 127
1104 error A complete log of this run can be found in: /home/dev/.npm/_logs/2023-08-30T21_38_31_938Z-debug-0.log

contents of the build.gradle.kts file

import com.github.gradle.node.npm.task.NpmTask

plugins {
    id("com.github.node-gradle.node")
}

// Configure the plugin to download and use specific Node version
node {
    version.set("18.17.1")
    npmInstallCommand.set("install")
    download.set(true)
}

// Register NpmTask that will do what "npm run build" command does.
tasks.register<NpmTask>("npmBuild") {
    dependsOn(listOf("npmInstall"))
    npmCommand.set(listOf("run","build"))
    inputs.dir("src")
}

tasks.named<NpmTask>("npmInstall") {
    args.set(listOf("--loglevel verbose"))
}

Gradle output shows error caused by statement shown below

Caused by: org.gradle.process.internal.ExecException: Process 'command '/home/dev/a/b/c/.gradle/nodejs/node-v18.17.1-linux-x64/bin/npm'' finished with non-zero exit value 127

Thank you in advance!

deepy commented 11 months ago

Are you able to check if the /home/dev/a/b/c/.gradle/nodejs/node-v18.17.1-linux-x64/bin/node file exists and if the nodeSetup task finished successfully? And then just to confirm, you're not on Alpine or another musl-based system right?

saurin-tech commented 11 months ago
> Task :a:clean UP-TO-DATE
> Task :b:nodeSetup UP-TO-DATE
> Task :b:npmSetup SKIPPED
> Task :b:npmInstall

File does exist at the location listed above but when I try to execute it in terminal I receive an error zsh: no such file or directory:

I'm trying to run this on NixOS

deepy commented 11 months ago

Ah, well I've got good and bad news for you. The bad news is you're gonna have to do some changes, but the good news I recently installed NixOS and have a basic idea of what those are 😀

You're going to need either a FHS or use something like nix-ld (or the very heavy approach of steam-run). Personally I'm using nix-ld together with nix-direnv to set what I need to work on this project. Unfortunately I need to run that flake with --impure since I don't know how to do that "properly", but this works well enough for me https://github.com/node-gradle/gradle-node-plugin/blob/1ea8bf828630c344ac8fc243e01f61c0beb223f4/flake.nix#L25-L28

Basically it's the same issue as with musl, if you run ldd on the node binary you'll see that it's expecting glibc and it's not being found

deepy commented 11 months ago

And technically there's nothing this plugin can do to accommodate NixOS, this is a conscious decision from their project and while this may be awkward from the perspective of users there's several workarounds Before I made the flake above I just ran steam-run zsh before developing and that worked mostly great