Jest: Unexpected token 'export'

[Problem/Question]
Hi ! When I run my tests using Jest, I got an SyntaxError: Unexpected token ‘export’ from node_modules/@sendbird/chat/sendbird.js:1.
I tried to add transformIgnorePatterns and moduleNameMapper to my jest config but it doesn’t work and I didn’t find any topic/thread about that.
Can you help me with that please ?

// If problem, please fill out the below. If question, please delete.
[SDK Version]
@sendbird/chat 4.1.0
[Reproduction Steps]

  • Import something from @sendbird/chat
  • Run tests with jest
    [Frequency]
    Always
    [Current impact]
    Blocking
1 Like

I am having the same issue. Running with jest and react-testing-library. My jest.config.js (I tried to get jest to ignore sendbird, but to no avail):

const config = { 
    testEnvironment: 'jsdom',
    moduleDirectories: ['node_modules', 'src'],
    moduleNameMapper: {
      "\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<r      ootDir>/mocks/fileMock.js",
      "\\.(css|less|scss|sass)$": "<rootDir>/mocks/fileMock.js"
    },  
    setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
    transformIgnorePatterns: [
        "node_modules/(?!@sendbird)"                                                                
    ]   
}

module.exports = config;

Build is managed by create-react-app, node version 18.8.0, jest 27.5.1, react 18.2.0.

I got it to run by explicitly adding the --transformIgnorePatterns "node_modules/(?!@sendbird)/chat" as a flag to react-scripts test. However, because sendbird now has to compile every time I run my tests, they take about 2GB of memory and 100% of my quad-core CPU for a good 30 seconds, which is just not sustainable when I have to run tests constantly.

Until the sendbird team pre-compiles their node module into standard JS with module.exports instead of export {} syntax, I’m afraid this makes it infeasible for me to use.

1 Like