{"id":587,"hash":"106fc8bfb6da969cb2a91a0ec21b1b547ad194fa29e0b4824d010908ce2374be","pattern":"JEST - SyntaxError: Unexpected token &#39;export&#39; with uuid library","full_message":"I used to solve similar errors while I was using Jest with only JavaScript, but currently I'm not able to do so with Typescript.\n\nAll my tests were running fine until I installed Puppeteer which requires @types/jest-environment-puppeteer, @types/puppeteer and @types/expect-puppeteer.\n\nAfter installing them, puppeteer tests are running perfectly, but other tests started to fail with below error.\n\n  D:\\...\\api\\node_modules\\uuid\\dist\\esm-browser\\index.js:1    \n    ({\"Object.<anonymous>\":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';\n                                                                                      ^^^^^^  \n\n    SyntaxError: Unexpected token 'export'\n\n      at Runtime.createScriptFromCode (../node_modules/jest-runtime/build/index.js:1796:14)   \n      at Object.require (../node_modules/@nestjs/common/decorators/core/injectable.decorator.js:4:16)\n\nWHAT I DID?\n\nallowJs: true on tsconfig.json and set the transformIgnorePatterns on jest configs. So that jest can compile files from node_modules/\nAfter that this error stopped but test failed for another strange reason.\nAnd worse is that test start time have increased too much.\n\nSo I left allowJs as in original setup and updated jest config from\n\n\"transform\": {\n   \"^.+\\\\.(t|j)s$\": \"ts-jest\"\n}\n\nto\n\n\"transform\": {\n   \"^.+\\\\.(t)s$\": \"ts-jest\"\n}\n\nSo currently ts-jest doesnt compile js files. But I think I am not able to make babel pick the transformation for js files. These are my jest configs:\n\n{\n  \"moduleFileExtensions\": [\"js\", \"json\", \"ts\"],\n  \"rootDir\": \".\",\n  \"testEnvironment\": \"node\",\n  \"testRegex\": \".e2e-spec.ts$\",\n  \"transform\": {\n    \"^.+\\\\.(t)s$\": \"ts-jest\",\n    \"^.+\\\\.(js|jsx)$\": \"babel-jest\"\n  },\n  \"transformIgnorePatterns\": [\"<rootDir>/node_modules/.+.(js|jsx)$\"]\n}","ecosystem":"npm","package_name":"typescript","package_version":null,"solution":"Thanks to this reply:\nhttps://stackoverflow.com/a/54117206/15741905\n\nI started googling for similar fixes and ended up here:\nhttps://github.com/uuidjs/uuid/issues/451\n\nAnd this solved my problem: https://github.com/uuidjs/uuid/issues/451#issuecomment-1112328417\n\n// jest.config.js\n{\n//................\n  moduleNameMapper: {\n    // Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451\n    \"uuid\": require.resolve('uuid'),\n  }\n}\n\nTough I would still be happy if there is solution to this by using jest-babel.\n\nBecause I had to carry jest configs from package.json to a seperate .js file.\n\nEdit:\nAccording to this github issue compatibility issue has been solved with the latest release of the uuid library.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/73203367/jest-syntaxerror-unexpected-token-export-with-uuid-library","votes":80,"created_at":"2026-04-19T04:51:22.584192+00:00","updated_at":"2026-04-19T04:51:22.584192+00:00"}