How to write Jest transformIgnorePatterns

后端 未结 4 2101
独厮守ぢ
独厮守ぢ 2021-02-19 02:52

I have this excpetion

Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it\'s not p         


        
4条回答
  •  梦谈多话
    2021-02-19 03:05

    I had a similar error while working on a project with jest, webpack, and vanilla js, so that error is thrown when jest encounters this line of code import '../css/styles.css'; in any /*?.js$/ file. I solved it by moving the jest configurations from the package.json file into a jest.config.js file with the following minimal configuration;

    // jest.config.js
    module.exports = 
      "moduleNameMapper": {
        "\\.(css|less|scss)$": "identity-obj-proxy"
      }
    }

    Then in babel.config.js

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

提交回复
热议问题