SyntaxError with Jest and React and importing CSS files

后端 未结 7 1144
-上瘾入骨i
-上瘾入骨i 2020-12-02 17:01

I am trying to get my first Jest Test to pass with React and Babel.

I am getting the following error:

SyntaxError: /Users/manueldupont/test/av

7条回答
  •  不思量自难忘°
    2020-12-02 17:19

    Similar situation, installing identity-object-proxy and adding it to my jest config for CSS is what worked for me.

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

    The specific error I was seeing:

    Jest encountered an unexpected token
    
    /Users/foo/projects/crepl/components/atoms/button/styles.css:1
    ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){.button { }
                                                                                             ^
    
    SyntaxError: Unexpected token .
    
      1 | import React from 'react';
    > 2 | import styles from './styles.css';
    

提交回复
热议问题