{"record":{"id":"a843d1edbed6755e","repo":"gatsbyjs/gatsby","slug":"this-plugin-file-is-using-both-commonjs-and-es6-mo","errorCode":null,"errorMessage":"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","messagePattern":"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: (.+?)\\.js","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/bootstrap/resolve-module-exports.ts","lineNumber":167,"sourceCode":"      // get foo from `module.exports.foo = bar`\n      if (t.isMemberExpression(nodeLeft.object)) {\n        const exp: t.MemberExpression = nodeLeft.object\n\n        if (\n          t.isIdentifier(exp.object) &&\n          t.isIdentifier(exp.property) &&\n          exp.object.name === `module` &&\n          exp.property.name === `exports`\n        ) {\n          isCommonJS = true\n          exportNames.push((nodeLeft.property as t.Identifier).name)\n        }\n      }\n    },\n  })\n\n  if (isES6 && isCommonJS && process.env.NODE_ENV !== `test`) {\n    report.panic(\n      `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\n\nThis didn't cause a problem in Gatsby v1 so you might want to review the migration doc for this:\nhttps://gatsby.dev/no-mixed-modules\n      `\n    )\n  }\n  return exportNames\n}\n\ninterface IResolveModuleExportsOptions {\n  mode?: `analysis` | `import`\n  resolver?: ModuleResolver\n  rootDir?: string\n}","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/bootstrap/resolve-module-exports.ts#L149-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pick one module system: convert all `module.exports.x`/`module.exports =` to `export`/`export default` (recommended), or convert all `export` to `module.exports`.","Re-run the build; the panic clears once the file is internally consistent.","Follow the linked migration doc https://gatsby.dev/no-mixed-modules for v1->v2 migration patterns."],"exampleFix":"// before (mixed)\nmodule.exports = { onCreatePage }\nexport const helper = () => {}\n// after (ES6 only)\nexport const helper = () => {}\nexport default { onCreatePage }","handlingStrategy":"validation","validationCode":"// Scan plugin files for mixed module systems before building\nconst fs = require('fs')\nconst src = fs.readFileSync(file, 'utf8')\nconst isES6 = /^\\s*export\\b/m.test(src)\nconst isCJS = /module\\.exports/.test(src)\nif (isES6 && isCJS) console.error(`${file} mixes CJS and ESM`)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt one module system per file; prefer ESM for new code.","Lint for mixed module systems (eslint-plugin-import has rules that help).","When migrating v1 plugins, fully remove module.exports before adding export."],"tags":["modules","commonjs","esm","plugin","syntax"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}