Skip to content

Newlines in arguments passed to node -e ... #1791

Open
chawyehsu/volta
#41

Description

@julienp

We ran into an issue when calling node -e ... with a script that contains new lines. pulumi/pulumi#16649

Repro:

main.go:

package main

import (
	"fmt"
	"os/exec"
)

func main() {
	argWithNewLines := `if (true) {
		console.log("it's true!");
	}`
	cmd := exec.Command("node", "-e", argWithNewLines)
	out, err := cmd.Output()
	if err != nil {
		fmt.Printf("Error: %s", err)
	}
	fmt.Println(string(out))
}

Run with:

go run main.go

When I have the Volta shim node.exe in the path, I get an error:

PS C:\Users\pulumiadmin> go run main.go
Error: exit status 1

With the actual node.exe on path, it works:

PS C:\Users\pulumiadmin> go run main.go
it's true!

Activity

  1. chriskrycho commented on Jul 12, 2024

    @chriskrycho
    Contributor

    Ah, thanks for the report! That is indeed quirky, and we should make sure we pass that through cleanly!

  2. karthest commented on Aug 10, 2024

    @karthest

    That's weired , it's totally OK on wsl2 ubuntu with volta v1.1.1 and node v20.12.2. Maybe the issue is related to a specific environment
    image

  3. julienp commented on Aug 10, 2024

    @julienp
    Author

    I am not much of a Windows user, from what I remember, I was able to reproduce this on a Windows (11 I think?) VM in Azure, not using WSL, no special config on the VM. We had at least 2 Pulumi users report an issue, where we narrowed down the root cause to this issue.

    I don't know how the Volta shims work, but I guess when running under WSL it's doing an exec syscall, but on plain Windows it will have to do something more intricate I believe?

  4. charlespierce commented on Aug 16, 2024

    @charlespierce
    Contributor

    Thanks for the reports, and the environment investigation! I suspect this might be related to the fact that we use cmd /C to execute the shimmed packages—I wonder if there's some strange argument handling there that is making it not parse correctly. I do a lot of my individual development on Windows, so should be able to investigate this weekend.

  5. charlespierce commented on Oct 3, 2024

    @charlespierce
    Contributor

    Didn't get to investigating that weekend 😅 However just now I did confirm, and from some digging online, I think this might be a hard limitation of cmd.exe, which we use internally to handle resolving executables on Windows.

    However, as mentioned in my most recent comment on #1761, that PR may provide a path forward to removing that use of cmd.exe entirely, which would (hopefully) resolve this in passing. I'm hoping to get an investigatory PR up that does that sometime today, though my flight is landing so I may run out of time!

  6. jabdinghoff commented on Apr 28, 2026

    @jabdinghoff

    After some crazy debugging I also found out that this results in the vaadin gradle plugin breaking
    https://github.com/vaadin/flow/blob/845056362fb468fc34de79d6da6acd2e50100776/flow-build-tools/src/main/java/com/vaadin/flow/server/frontend/FrontendTools.java#L528-L540

    This basically runs:

    C:\Program Files\Volta\node.exe --eval "var jsonPath = require.resolve('vite/package.json');\nvar json = require(jsonPath);\nconsole.log(path.resolve(path.dirname(jsonPath),json.bin['vite']));\n"

    And the \n here drops the console.log so it returns nothing and this results in this cryptic error:

    * What went wrong:
    Execution failed for task ':libraries:app:vaadinBuildFrontend'.
    > Unable to locate Vite executable by path 'C:\Users\redacted\.gradle\daemon\9.0.0'. Double check that the plugin is executed correctly
    

    The empty string gets replaced with the cwd so it shows the gradle daemon directory.

    Mostly writing this out here so other people who ran into this can find this googling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions