You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

在iTerm(zsh)环境下运行ts-node提示“command not found”,是否需要更新PATH?

Fixing "zsh: command not found: ts-node" After Global Installation

Hey there, let's troubleshoot why your zshell can't find ts-node even after you've installed it globally with npm. Here's a step-by-step solution:

Step 1: Locate npm's global package directory

First, we need to find where npm installs global packages. Run this command in your terminal:

npm config get prefix

This will output a path (e.g., /Users/myname/.npm-global or /usr/local). The bin folder containing ts-node sits directly under this prefix—so if your prefix is /Users/myname/.npm-global, the full path to the bin folder is /Users/myname/.npm-global/bin.

Step 2: Check if this bin path is in your $PATH

Looking at the $PATH output you shared, none of the listed paths match the npm global bin directory we just found. That's exactly why zsh can't locate ts-node.

Step 3: Add the npm bin path to your $PATH

Temporary fix (for current terminal session only)

Run this command to immediately add the missing path:

export PATH="$PATH:$(npm config get prefix)/bin"

Now test if ts-node works by running:

ts-node --version

If this works, move on to making the change permanent so you don't have to repeat this every time you open a terminal.

Permanent fix (persists across terminal sessions)

  1. Open your zsh configuration file (usually ~/.zshrc) in a text editor:
open ~/.zshrc
  1. Add this line at the bottom of the file:
export PATH="$PATH:$(npm config get prefix)/bin"
  1. Save the file and apply the changes right away by running:
source ~/.zshrc

Step 4: Verify the fix

Run these commands to confirm everything is working as expected:

which ts-node
# Should output the full path to ts-node (e.g., /Users/myname/.npm-global/bin/ts-node)
ts-node --version
# Should display your installed ts-node version

Alternative: Check for permission issues

If the above steps don't resolve the problem, you might have hit permission errors during installation. Try reinstalling ts-node and typescript with elevated permissions (note: using sudo is a quick check, but for long-term best practice, consider configuring npm to use a user-specific directory instead of system-wide):

sudo npm install -g typescript ts-node

内容的提问来源于stack exchange,提问作者Brian Yoon

火山引擎 最新活动