nx
nx copied to clipboard
Vercel deployments report "hostname: command not found"
Current Behavior
When executing an nx command (e.g., nx build my-app
) during a deployment to Vercel, the following error output appears:
/bin/sh: line 1: hostname: command not found
Using the --skip-nx-cache flag (e.g., nx build my-app --skip-nx-cache
) removes the error.
This seems to be a common issue with Vercel (example).
Expected Behavior
nx commands execute successfully during Vercel deployments
GitHub Repo
No response
Steps to Reproduce
- Deploy an application to Vercel using nx
- Observe the error output in the deployment log
Nx Report
Node : 20.12.0
OS : linux-x64
pnpm : 8.15.5
nx : 17.2.0
@nx/js : 17.2.0
@nx/jest : 17.2.0
@nx/linter : 17.2.0
@nx/eslint : 17.2.0
@nx/workspace : 17.2.0
@nx/cypress : 17.2.0
@nx/devkit : 17.2.0
@nx/eslint-plugin : 17.2.0
@nx/next : 17.2.0
@nx/playwright : 17.2.0
@nx/react : 17.2.0
@nx/storybook : 17.2.0
@nrwl/tao : 17.2.0
@nx/vite : 17.2.0
@nx/web : 17.2.0
nx-cloud : 16.5.2
typescript : 5.3.3
Failure Logs
No response
Package Manager Version
No response
Operating System
- [ ] macOS
- [X] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
No response
Have you tried invoking nx via npx nx build my-app
?
Without npx
you'll have to install nx
globally. But for the deploy, you can use npx
to resolve Nx from node_modules
Same error using pnpm nx ....
. Since the version of nx
reported by nx report
exactly matches my package.json (and is not the latest), I believe it was already running from node_modules.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐
Not stale, still happening
Not stale, still happening
I've same problem and I did a workaround to fix:
Edit or create a file called vercel.json
in project root and add installCommand
into it (this command runs before build command):
{
"installCommand": "yum install hostname && npm ci",
}
Note: I'm using npm ci
but you can change to npm install
.
Note 1: I've tested it in Node JS 18.x, which uses Amazon Linux 2 Image, so maybe you need to change yum install
command if Node JS 20.x uses another kind of image.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐
I totally believe the work around of installing hostname
works, however, this should not be necessary. This points to a bad assumption in the nx
binary.
i have the same problem with angular + nx + vercel
/bin/sh: line 1: hostname: command not found
If i change some field in Build & Development Settings - its fixed for one build, and i override every time some field for run build - its work... life hack :D
I have to press "redeploy" for all of my builds due to this issue.
Add yum install hostname &&
to my install command makes Vercel hang seemingly indefinitely
+1 on the builds handing. Only a manual redeploy works for me too.
This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! ๐
Still reproducing
Still happening with our project, we need to redeploy every single deployment. Using --skip-nx-cache
does remove the error, and allows the build to succeed.
Still happening.
Like @alancpazetto, I added this installCommand
, but it also needed the -y
flag.
{
"installCommand": "yum install -y hostname && npm ci",
}
This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! ๐
Just started running into this after upgrading sentry from v7 to v8 using experimental.instrumentationHook in next config
This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! ๐
Still happening.
Like @alancpazetto, I added this
installCommand
, but it also needed the-y
flag.{ "installCommand": "yum install -y hostname && npm ci", }
Still happening - above solved it for me
This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! ๐
Still happening - above solved it for me
Here's what worked for me
- Use
others
in project template - Create
vercel.json
(if not present already) and add the following
{
"installCommand": "yum install -y hostname && npm ci",
}
PS: You can also use npm install
instead of npm ci
thanks to @alancpazetto
Hi everyone! I've been debugged this issue and found the causes.
- This occur only when project uses Nx Cloud (I've tested with and without NxCloud)
- NxCloud downloads a bundler in runtime remotly from https://cloud.nx.app/nx-cloud/static/client-bundle this is because we didn't find
hostname
in this repo (probably client-bundle is a private repo) - The client bundle uses this package node-machine-id
- The node-machine-id calls shell to get hostname when machine is Linux
- The hostname package isn't installed in Vercel , here the pre-installed packages
- As this package is private, I couldn't find this code to try fix it
So, i've some questions about it:
- Does Nx Cloud really need to use this package? Because this cause a machine dependency, e.g. this issue with Vercel
- Is this problema related with Nx, Vercel or node-machine-id? IMHO less dependency Nx Cloud causes, better it is
Note that this error doesn't cause build fail, but could be wrong interpreted
As workaround, the only way to fix or suppress error is adding yum install -y hostname
in installCommand
(depends of Vercel Machine you need to use dnf
instead yum
).
I'm marking @ndcunningham just because you are assinged to this issue.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.