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?

【jestエラー】Configuration error: Could not locate module ./App.css mapped as: identity-obj-proxy.

Posted at

はじめに

jestでテスト実装中に以下のエラーが出ました。

問題

エラーメッセージ
Configuration error:
    
    Could not locate module ./App.css mapped as:
    identity-obj-proxy.
    
    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/\.(css|less)$/": "identity-obj-proxy"
      },
      "resolver": undefined
    }

スクリーンショット 2025-02-19 23.28.07.png

解決方法

以下コマンドを実行
// テスト実行時のスタイルファイル(CSS/SCSS/LESS)をモック化するためのパッケージを追加
npm install --save-dev identity-obj-proxy
jest.config.js
export default {
  preset: "ts-jest",
  testEnvironment: "jsdom",
  setupFilesAfterEnv: ["./jest.setup.ts"],
  transform: {
    "^.+\\.(ts|tsx)$": "ts-jest",
  },
  moduleNameMapper: {
    "\\.(css|less|scss)$": "identity-obj-proxy", //scssを追加
  },
};

おわりに

テスト実行時のスタイルファイル(CSS/SCSS/LESS)をモック化するためのパッケージがないために起きたエラーでした。

今回は記事を見つけることができなかったのでCopilotに@workspaceでエラーについて聞くと一瞬で解決できました。

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?