Node "SyntaxError: Unexpected token export" in CI
Node parsed a file as CommonJS and hit an export statement, which is not valid CommonJS syntax. This is the export-side twin of "Cannot use import statement outside a module".
What this error means
Loading a module fails with "SyntaxError: Unexpected token 'export'", frequently pointing into a node_modules package that shipped raw ESM.
/app/node_modules/some-esm-lib/index.js:1
export default function () {}
^^^^^^
SyntaxError: Unexpected token 'export'Common causes
ESM export syntax in a CommonJS-parsed file
The file uses export but Node treats it as CommonJS because there is no "type": "module" or .mjs extension.
A dependency published untranspiled ESM
A package shipped ESM source that a CommonJS consumer required directly, so Node parses export and throws.
How to fix it
Run the file as an ES module
For your own code, set "type": "module" or use .mjs so export is valid.
{
"type": "module"
}Handle an ESM-only dependency correctly
If a dependency is ESM-only, import it via dynamic import() from CJS, or switch your project to ESM.
const lib = (await import('some-esm-lib')).default;How to prevent it
- Keep the module format consistent across your package.
- Check whether a dependency ships CJS, ESM, or both.
- Use dynamic import for ESM-only deps from CommonJS code.