最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shell - Xcode build phase run script doesn't have access to node - Stack Overflow

programmeradmin3浏览0评论

I have a custom "Run Script" step in my Xcode projects Build Phases which does the following:

#!/bin/zsh

set -e

# move to the node project directory
cd ~/my-node-project

# build js project
npm run build

echo "[BuildPhase] finished!"

However, it seems that the Shell environment Xcode has access to doesn't include several environment variables such as the paths to node, asdf or even homebrew.

I have changed the shell to use zsh which is the default on my machine, however, even when I attempt to source my ~/.zshrc in the custom build phase, I get the following issue:

/Users/asleepace/.zshrc:52: command not found: brew

I have a custom "Run Script" step in my Xcode projects Build Phases which does the following:

#!/bin/zsh

set -e

# move to the node project directory
cd ~/my-node-project

# build js project
npm run build

echo "[BuildPhase] finished!"

However, it seems that the Shell environment Xcode has access to doesn't include several environment variables such as the paths to node, asdf or even homebrew.

I have changed the shell to use zsh which is the default on my machine, however, even when I attempt to source my ~/.zshrc in the custom build phase, I get the following issue:

/Users/asleepace/.zshrc:52: command not found: brew
Share Improve this question asked Mar 17 at 23:54 AsleepaceAsleepace 3,7652 gold badges27 silver badges39 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The solution was to add homebrew to the PATH adding the following at the top of the file:

export PATH="$PATH:/opt/homebrew/bin"

Once that was added, the source ~/.zshrc command succeeded, here is the full script for context:

#!/bin/zsh

set -e

# add homebrew location to path (location may vary)
export PATH="$PATH:/opt/homebrew/bin"

# source zshrc file (could also be ~/.bashrc)
source ~/.zshrc

# move to project directory
cd ~/my-node-project

echo "[BuildPhase] building application..."

# build project
npx vite build

echo "[BuildPhase] finished!"
发布评论

评论列表(0)

  1. 暂无评论