Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Jest tests fails with react-dnd: SyntaxError: Unexpected token 'export'

Suffering from a weird error and currently can't get through. So When I run tests console throws:

/var/www/html/node_modules/react-dnd/dist/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from './core/index.js';
                                                                                  ^^^^^^


SyntaxError: Unexpected token 'export'

I Googled. People were discussing and saying module mappers should be added, so I added this code inside jest config:

'^react-dnd$': '<rootDir>/node_modules/react-dnd/dist/cjs',
'^react-dnd-html5-backend$': '<rootDir>/node_modules/react-dnd-html5-backend/dist/cjs',
'^dnd-core$': '<rootDir>/node_modules/dnd-core/dist/cjs',

Another error thrown:

 Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^react-dnd$/": "react-dnd/dist/cjs"
      },
      "resolver": undefined
    }

If anyone has solved this with react-dnd please help me out! :))

like image 796
Rollin Avatar asked Jun 25 '26 19:06

Rollin


1 Answers

Try adding this to package.json:

"jest": {
    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!react-dnd|core-dnd|@react-dnd|dnd-core|react-dnd-html5-backend)"
    ]
}

or, if your project uses it, to jest.config.js:

"transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!react-dnd|core-dnd|@react-dnd|dnd-core|react-dnd-html5-backend)"
    ]
like image 183
Bavin Edwards Avatar answered Jun 28 '26 09:06

Bavin Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!