1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node.jsがTSファイル(.ts)を直接実行できない時のエラー【TypeError: Unknown file extension ".ts"】

Posted at

背景

毎朝6時にSupabaseのデータを削除するバッチをGitHub Actionsのcronジョブで実行する課題に取り組んでいました。

その際に、Node.jsがTypeScriptファイル(.ts)を直接実行できないため発生したエラーに遭遇しました。

TypeError: Unknown file extension ".ts"

GitHub Actionsの標準Node.js環境では、TypeScriptファイルを扱う設定が不足していたことが原因でした。

解決策

以下の点を考慮してtsxを使用して対応しました。

  • tsxは追加設定なしでTypeScriptファイルを直接実行できる
  • GitHub Actions環境でも安定して動作する

tsx はTypeScript Executeの略で、 TypeScriptを実行するための Node.js 拡張機能です。

修正内容

- name: Install tsx
  run: npm install -g tsx

- name: Run delete script
  run: npx tsx ./batch/index.ts

まとめ

GitHub ActionsでTypeScriptファイルを実行する際は、tsxを使用することでNode.js由来の拡張子エラーを回避できます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?