はじめに
今回はGitHub ActionsでBuild時に起きたエラーについて書いていきます。
問題
エラーメッセージ
error TS2688: Cannot find type definition file for '@testing-library/jest-dom'.
The file is in the program because:
Entry point of type library '@testing-library/jest-dom' specified in compilerOptions
error TS2688: Cannot find type definition file for 'jest'.
The file is in the program because:
Entry point of type library 'jest' specified in compilerOptions
error TS2688: Cannot find type definition file for 'node'.
The file is in the program because:
Entry point of type library 'node' specified in compilerOptions
Error: Process completed with exit code 1.
main.yml
# ビルドジョブ - テスト完了後に実行
build:
name: Build
needs: [test] # テストジョブが成功した後に実行
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
# プロジェクトのビルド
- name: Build
run: npm run build
# ビルド成果物をアップロード
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-files
path: dist/ # ビルド出力ディレクトリ
解決方法
main.yml
# ビルドジョブ - テスト完了後に実行
build:
name: Build
needs: [test] # テストジョブが成功した後に実行
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
# 型定義のインストールを追加
+ - name: Install type definitions
+ run: npm install --save-dev @types/jest @types/node @types/testing-library__jest-dom
# プロジェクトのビルド
- name: Build
run: npm run build
# ビルド成果物をアップロード
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-files
path: dist/ # ビルド出力ディレクトリ
おわりに
Vite環境でTypeScriptを採用してのCI/CDは初めてで型定義のインストールが必要だと分かり、上記のコードを追加して解決できました。