jest가 react 읽지 못함 오류

김남경·2022년 12월 14일

react

목록 보기
12/37

ERROR
SyntaxError: App.test.js: Support for the experimental syntax 'jsx' isn't currently enabled

✅ npm i @babel/preset-react –save-dev
✅ babel.config.js 추가(package.json 있는 곳)

module.exports = {
    presets: [
      '@babel/preset-react',
      [ 
        '@babel/preset-env',
        {
          targets: {
            node: 'current',
          },
        },
      ],
    ],
  };

jsx해결

ERROR
SyntaxError: Invalid or unexpected token
-> import "./App.css";

✅ npm install -D identity-obj-proxy
✅ jest.config.js 추가

module.exports = {
  moduleNameMapper: {
    "\\.(css|less|scss|sass)$": "identity-obj-proxy",
  }

};

css import해결

ERROR
ReferenceError: React is not defined

✅ babel.config.js 추가

module.exports = {
  presets: [
    ["@babel/preset-react", { runtime: "automatic" }],
};

react is not defined

ERROR
SyntaxError: Cannot use import statement outside a module

✅ jest.config.js 추가

module.exports = {
  modulePathIgnorePatterns: ["<rootDir>/app.test.js위치 폴더"],

};

modulePathIgnorePatterns

profile
기본에 충실하며 앞으로 발전하는

0개의 댓글