gatsbyjs/gatsby · error

This plugin file is using both CommonJS and ES6 module syste

Error message

This plugin file is using both CommonJS and ES6 module systems together which we don't support.\nYou'll need to edit the file to use just one or the other.\n\nplugin: ${modulePath}.js

What it means

Thrown by resolve-module-exports when static analysis detects that a plugin file uses BOTH ES6 exports (export ...) AND CommonJS (module.exports) in the same file. Gatsby does not support mixed module systems, so the build panics with the plugin path and a migration-doc link. Skipped under NODE_ENV=test.

Source

Thrown at packages/gatsby/src/bootstrap/resolve-module-exports.ts:167

      // get foo from `module.exports.foo = bar`
      if (t.isMemberExpression(nodeLeft.object)) {
        const exp: t.MemberExpression = nodeLeft.object

        if (
          t.isIdentifier(exp.object) &&
          t.isIdentifier(exp.property) &&
          exp.object.name === `module` &&
          exp.property.name === `exports`
        ) {
          isCommonJS = true
          exportNames.push((nodeLeft.property as t.Identifier).name)
        }
      }
    },
  })

  if (isES6 && isCommonJS && process.env.NODE_ENV !== `test`) {
    report.panic(
      `This plugin file is using both CommonJS and ES6 module systems together which we don't support.
You'll need to edit the file to use just one or the other.

plugin: ${modulePath}.js

This didn't cause a problem in Gatsby v1 so you might want to review the migration doc for this:
https://gatsby.dev/no-mixed-modules
      `
    )
  }
  return exportNames
}

interface IResolveModuleExportsOptions {
  mode?: `analysis` | `import`
  resolver?: ModuleResolver
  rootDir?: string
}

View on GitHub (pinned to 8b06340921)

Solutions

  1. Pick one module system: convert all `module.exports.x`/`module.exports =` to `export`/`export default` (recommended), or convert all `export` to `module.exports`.
  2. Re-run the build; the panic clears once the file is internally consistent.
  3. Follow the linked migration doc https://gatsby.dev/no-mixed-modules for v1->v2 migration patterns.

Example fix

// before (mixed)
module.exports = { onCreatePage }
export const helper = () => {}
// after (ES6 only)
export const helper = () => {}
export default { onCreatePage }
Defensive patterns

Strategy: validation

Validate before calling

// Scan plugin files for mixed module systems before building
const fs = require('fs')
const src = fs.readFileSync(file, 'utf8')
const isES6 = /^\s*export\b/m.test(src)
const isCJS = /module\.exports/.test(src)
if (isES6 && isCJS) console.error(`${file} mixes CJS and ESM`)

Prevention

When it happens

Trigger: A plugin/gatsby-node file contains at least one `export ...` (or `export default`) statement AND at least one `module.exports = ...` / `module.exports.x = ...` expression; static analysis sets both isES6 and isCommonJS true.

Common situations: Migrating a v1 CommonJS plugin to ES6 by adding `export` without removing the old `module.exports`; copy-pasting snippets from different module-style sources into one file; bundlers/transpilers emitting both forms.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/a843d1edbed6755e. Report an issue: GitHub.