You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ts-node/ts_node命令未被识别问题求助(已尝试常见方案)

问题描述

运行ts_node命令时触发以下错误:

ts_node : The term 'ts_node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • ts_node
  • + CategoryInfo          : ObjectNotFound: (ts_node:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    

已按以下方式完成ts-node的本地及全局安装:

# 本地项目安装
npm install -D typescript
npm install -D ts-node

# 全局安装
npm install -g typescript
npm install -g ts-node

环境配置:Node.js 18、Windows 11、npm 10.1.0、TypeScript 5.2.2

解决方案
  • 修正命令拼写:ts-node的正确调用命令是ts-node(连字符分隔),而非ts_node(下划线),先确认是否因拼写错误导致问题。
  • 全局安装后校验环境变量:
    1. 在PowerShell中执行npm config get prefix,获取npm全局包的安装根路径。
    2. 检查该路径下的node_modules/.bin目录是否已加入系统环境变量Path。
    3. 若未添加,手动配置:右键「此电脑」→「属性」→「高级系统设置」→「环境变量」,在系统变量的Path列表中新增上述路径,之后重启PowerShell生效。
  • 本地安装的正确运行方式:
    本地安装的ts-node无法直接全局调用,可通过两种方式运行:
    • 使用npx调用:npx ts-node your-file.ts
    • 在项目package.json中添加脚本:
      "scripts": {
        "dev": "ts-node src/index.ts"
      }
      
      执行npm run dev即可运行指定文件。
  • 修复全局包安装异常:
    若全局安装存在权限或缓存问题,执行以下命令重新安装:
    npm uninstall -g ts-node typescript
    npm install -g ts-node typescript --force
    
  • 清理npm缓存后重装:
    尝试清理缓存后重新安装,排除缓存损坏导致的问题:
    npm cache clean --force
    npm uninstall -g ts-node typescript
    npm install -g ts-node typescript
    

内容的提问来源于stack exchange,提问作者k.k

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 02:40:00