{"id":591,"hash":"e16327f65f0f8e4d037371777805cfb4ea299464ff7a4693653f99549e4f096e","pattern":"jest: Test suite failed to run, SyntaxError: Unexpected token import","full_message":"This is my jest configuration from the package.json file:\n\n\"jest\": {\n    \"automock\": false,\n    \"browser\": true,\n    \"moduleNameMapper\": {\n      \"\\\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$\": \"./app/tests/mocks/FileMock.js\",\n      \"\\\\.(css|less)$\": \"identity-obj-proxy\"\n    },\n    \"moduleFileExtensions\": [\n      \"js\",\n      \"jsx\"\n    ],\n    \"moduleDirectories\": [\n      \"node_modules\"\n    ],\n    \"transform\": {\n      \"^.+\\\\.jsx?$\": \"./node_modules/babel-jest\",\n      \"\\\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$\": \"./app/tests/mocks/FileTransformer.js\"\n    },\n    \"testEnvironment\": \"jsdom\",\n    \"testPathDirs\": [\n      \"./app/tests\"\n    ],\n    \"testRegex\": \".*.test.js\",\n    \"verbose\": true\n  }\n\nAnd the .babelrc file located in my root folder:\n\n{\n  \"plugins\": [\"syntax-dynamic-import\", \"transform-runtime\"],\n  \"presets\": [\n    [\n      \"es2015\",\n      {\n        \"modules\": false\n      }\n    ],\n    \"react\",\n    \"stage-0\"\n  ],\n  \"env\": {\n    \"start\": {\n      \"presets\": [\n        \"react-hmre\"\n      ]\n    }\n  }\n}\n\nAccording to the documentation found at the jest getting started page this is everything I need for babel to work it's magic.\n\nRegardless, this test:\n\nimport React from 'react';\nimport {shallow} from 'enzyme';\nimport Landing from '../components/Landing.component';\n\ndescribe('<Landing/>', () => {\n  it('should render a header to the page', () => {\n    const landing = shallow(<Landing/>);\n    expect(landing.find('h1').text()).toBe('This is the Landing component');\n  });\n});\n\nreturns:\n\nFAIL  app/tests/Landing.component.test.js   \n ● Test suite failed to run\n\n   /Users/shooshte/PersonalProjects/surviveJS/app/tests/Landing.component.test.js:1\n   ({\"Object.<anonymous>\":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';\n                                                                                            ^^^^^^\n   SyntaxError: Unexpected token import\n\n     at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:320:12)\n\nWhat am I doing wrong?","ecosystem":"npm","package_name":"reactjs","package_version":null,"solution":"Jest sets the env variable to test, so I had to add my presets to the env setting in .babelrc:\n\n{\n  \"plugins\": [\"syntax-dynamic-import\", \"transform-runtime\"],\n  \"presets\": [\n    [\n      \"es2015\",\n      {\n        \"modules\": false\n      }\n    ],\n    \"react\",\n    \"stage-0\"\n  ],\n  \"env\": {\n    \"start\": {\n      \"presets\": [\n        \"react-hmre\"\n      ]\n    },\n    \"test\": {\n      \"presets\": [\"es2015\", \"react\", \"stage-0\"]\n    }\n  }\n}","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/41725796/jest-test-suite-failed-to-run-syntaxerror-unexpected-token-import","votes":60,"created_at":"2026-04-19T04:51:22.587182+00:00","updated_at":"2026-04-19T04:51:22.587182+00:00"}