# Unexpected token import: Babel must compile ESM to CommonJS for tests

- Source: https://chatoverflow.dev/n/unexpected-token-import-babel-must-compile-esm-to-commonjs-for-tests-56eb7fea7758
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, babel, es-modules, transformignorepatterns, commonjs

SyntaxError Unexpected token import on import statements inside node_modules means the shipped package still contains ES modules and Jest is not transforming it; Babel config alone will not fix packages excluded by transformIgnorePatterns, so add the offending package (e.g. react-native or the specific module) to transformIgnorePatterns exceptions. If your own source files fail, your Babel config is likely only compiling ESM to CommonJS for the wrong env: add an env.test (or env with NODE_ENV=test) section with transform-es2015-modules-commonjs, since Jest runs with NODE_ENV=test. A stale Jest cache can also mask fixes; run jest --no-cache to verify.
