Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-cdk-cli: CDK fails if node executable has a space in the path #28582

Closed
zastrowm opened this issue Jan 4, 2024 · 4 comments
Closed

aws-cdk-cli: CDK fails if node executable has a space in the path #28582

zastrowm opened this issue Jan 4, 2024 · 4 comments
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort p2 package/tools Related to AWS CDK Tools or CLI

Comments

@zastrowm
Copy link

zastrowm commented Jan 4, 2024

Describe the bug

The CDK fails to execute any command that uses a sub-process when the node executable has a space in its path. The error is non-obvious as to the cause.

Expected Behavior

The CDK commands should work the same whether or not the node executable has a space in its path.

Current Behavior

A seemingly random error occurs running cdk commands:

❯ npm run release-synthesize
> cdk synthesize --output dist/cdk.out --app dist/src/resources/index.js

/bin/sh: /Users/{username}/Library/Application: No such file or directory
Error: Subprocess exited with error 127
    at ChildProcess.<anonymous> (/{path}/node_modules/aws-cdk/lib/api/cxapp/exec.ts:132:9)
    at ChildProcess.emit (node:events:517:28)
    at ChildProcess.emit (node:domain:489:12)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:292:12)

Reproduction Steps

  • Put node somewhere with a space in the path
  • Then using that version of node in your path, execute the cdk command.

On MacOS I use FNM as my node module and this was my node path:

/Users/{UserName}/Library/Application Support/fnm/node-versions/v18.18.2/installation/bin/node dist/src/resources/index.js

Possible Solution

This seems to be caused by the line where the commandLine params are joined:

await exec(commandLine.join(' '));

I monkey-patched my local CDK install to quote values which have a space in them:

Tip

it's worth noting that the exec.js may not be the file to fix this in - I needed to modify index.js instead

await exec(commandLine.map(it => it.includes(" ") ? `"${it}"` : it).join(' '));

which allowed all my CDK commands to execute successfully and without errors.

Additional Information/Context

This took me a while to debug because I had no context as to what sub-process was failing. Immediately above the line there is some logging of the environment in debug mode - I'd suggest also emitting the path to the command line as well before calling exec; that would have at least alerted me to the fact that it was a node problem.

CDK CLI Version

2.32.1 (build 79cbe95)

Framework Version

No response

Node.js Version

v18.18.2

OS

MacOS

Language

TypeScript

Language Version

No response

Other information

No response

@zastrowm zastrowm added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 4, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jan 4, 2024
@pahud
Copy link
Contributor

pahud commented Jan 5, 2024

Thank you for the report. Yes I think we should fix it.

@pahud pahud added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 5, 2024
@albertothedev
Copy link

I have a similar error.

@pahud pahud added @aws-cdk/core Related to core CDK functionality cli Issues related to the CDK CLI labels Apr 10, 2024
@vinayak-kukreja vinayak-kukreja self-assigned this Apr 24, 2024
@vinayak-kukreja vinayak-kukreja added p2 effort/medium Medium work item – several days of effort and removed p1 effort/small Small work item – less than a day of effort labels May 7, 2024
@vinayak-kukreja
Copy link
Contributor

Hey, thank you for reporting this issue.

This issue as mentioned is being caused by a space being present in the path for node executable. Looking at node github repository issues, it looks like this is a known issue with how node handles spaces in paths. And for CDK, this occurs here.

We currently do not have any plans to fix this on our end. Our recommendation for a workaround here would be to install node at a path which does not have spaces in it.

Copy link

github-actions bot commented May 7, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants