nx icon indicating copy to clipboard operation
nx copied to clipboard

Vercel deployments report "hostname: command not found"

Open ZebraFlesh opened this issue 10 months ago โ€ข 16 comments

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

  1. Deploy an application to Vercel using nx
  2. 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

ZebraFlesh avatar Apr 04 '24 23:04 ZebraFlesh

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

FrozenPandaz avatar Apr 05 '24 19:04 FrozenPandaz

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.

ZebraFlesh avatar Apr 05 '24 22:04 ZebraFlesh

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! ๐Ÿ™

github-actions[bot] avatar Apr 20 '24 00:04 github-actions[bot]

Not stale, still happening

ZebraFlesh avatar Apr 20 '24 00:04 ZebraFlesh

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.

alancpazetto avatar Apr 22 '24 17:04 alancpazetto

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! ๐Ÿ™

github-actions[bot] avatar May 07 '24 00:05 github-actions[bot]

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.

ZebraFlesh avatar May 07 '24 03:05 ZebraFlesh

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

eurusik avatar May 08 '24 16:05 eurusik

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

hcharley avatar May 09 '24 00:05 hcharley

+1 on the builds handing. Only a manual redeploy works for me too.

cbrinicombe13 avatar May 10 '24 16:05 cbrinicombe13

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! ๐Ÿ™

github-actions[bot] avatar May 18 '24 00:05 github-actions[bot]

Still reproducing

eurusik avatar Jun 05 '24 12:06 eurusik

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.

jourdanhaines avatar Jun 07 '24 01:06 jourdanhaines

Still happening.

Like @alancpazetto, I added this installCommand, but it also needed the -y flag.

{
  "installCommand": "yum install -y hostname && npm ci",
}

johnhwhite avatar Jun 08 '24 18:06 johnhwhite

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! ๐Ÿ™

github-actions[bot] avatar Jun 16 '24 00:06 github-actions[bot]

Just started running into this after upgrading sentry from v7 to v8 using experimental.instrumentationHook in next config

cyrus-za avatar Jun 27 '24 18:06 cyrus-za

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! ๐Ÿ™

github-actions[bot] avatar Jul 05 '24 00:07 github-actions[bot]

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

hitwill avatar Jul 05 '24 07:07 hitwill

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! ๐Ÿ™

github-actions[bot] avatar Jul 13 '24 00:07 github-actions[bot]

Still happening - above solved it for me

alancpazetto avatar Aug 06 '24 10:08 alancpazetto

Here's what worked for me

  1. Use others in project template
  2. 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

krishnabose02 avatar Aug 16 '24 23:08 krishnabose02

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.

alancpazetto avatar Aug 20 '24 11:08 alancpazetto

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.

github-actions[bot] avatar Sep 20 '24 00:09 github-actions[bot]