node-gradle / gradle-node-plugin

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

Detection of unsupported environments #325

Open chkpnt opened 1 month ago

chkpnt commented 1 month ago

I'm using the following build.gradle.kts:

node {
    download = true
    version = "18.15.0"
    workDir = layout.buildDirectory.dir("nodejs")
}

val npmExec = if (System.getProperty("os.name").lowercase().contains("windows")) "/npm.cmd" else "/bin/npm"

spotless {
    isEnforceCheck = false

    format("javascript") {
        target("**/*.js", "**/*.json", "**/*.json5", "**/*.css")
        prettier(
            mapOf(
                "prettier" to "3.2.5",
                "prettier-plugin-multiline-arrays" to "3.0.4",
            )
        )
            .npmExecutable(
                "${
                    tasks.named<NpmSetupTask>("npmSetup").get().npmDir.get()
                }$npmExec"
            )
            .config(
                mapOf(
                    "printWidth" to 120,
                    "tabWidth" to 4,
                    "multilineArraysWrapThreshold" to 1,
                    "plugins" to listOf("prettier-plugin-multiline-arrays")
                )
            )
    }
}

When running spotlessCheck in an openjdk:11-image, I'm getting the following error:

/usr/bin/env: ‘node’: No such file or directory

149 gave me the correct hint that the image is the culprit. After moving to eclipse-temurin:11-jdk (the openjdk-images are anyways deprecated), everything works fine.

But the issue doesn't seem to be related to musl, as openjdk:11 is based on Debian 11.4.

$ docker run -it --rm openjdk:11 ldd --version
ldd (Debian GLIBC 2.31-13+deb11u3) 2.31
[...]

eclipse-temurin:11-jdk is based on Ubuntu 24.04 and I haven't digged deeper, why I'm getting ‘node’: No such file or directory only on one system.

But as it took me some time 'til I figured out that the environment is the issue, I suggest gradle-node-plugin to detect problematic environments (musl et al) and print a warning.

deepy commented 1 month ago

I wonder if this is a bug or a timing issue, because testing node 18.15.0 on openjdk:11 (through docker with --platform linux/amd64) seems to work on my machine But it's strange that it works with the new image (and with both being multi-platform that rules out platform shenanigans) 🤔