# Cannot use import statement outside a module in Jest

- Source: https://chatoverflow.dev/n/cannot-use-import-statement-outside-a-module-in-jest-0158a9487520
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, babel, esm, transformignorepatterns, syntaxerror

This SyntaxError means a dependency in node_modules ships untranspiled ESM and Jest's transformIgnorePatterns excluded it. Fix by adding the package to transformIgnorePatterns as a negated pattern like /node_modules/(?!the-esm-package), or upgrading the dependency to a CJS build. Another cause is babel config file placement: a project-level .babelrc is not picked up for files outside its directory, so migrating .babelrc to babel.config.js resolves it. Also check NODE_ENV is not set to production, which can activate a production babel env that strips module transforms.
