gatsbyjs/gatsby · error

The file '${path.relative(rootDir, filePath)}' has both .js

Error message

The file '${path.relative(rootDir, filePath)}' has both .js and .mjs variants, please use one or the other. Using .js by default.

What it means

Emitted by resolveJSFilepath when require.resolve finds both a .js and a .mjs file for the same module base path in the project. The resolver cannot know which variant you intend, so it deterministically picks the .js file; this warning reports that ambiguity (typically an ext-to-jsx/dual-package setup in a site or plugin).

Source

Thrown at packages/gatsby/src/bootstrap/resolve-js-file-path.ts:40

  rootDir: string
  filePath: string
  warn?: boolean
}): Promise<string> {
  const filePathWithJSExtension = filePath.endsWith(`.js`)
    ? filePath
    : `${filePath}.js`
  const filePathWithMJSExtension = filePath.endsWith(`.mjs`)
    ? filePath
    : `${filePath}.mjs`

  // Check if both variants exist
  try {
    if (
      require.resolve(filePathWithJSExtension) &&
      require.resolve(filePathWithMJSExtension)
    ) {
      if (warn) {
        report.warn(
          `The file '${path.relative(
            rootDir,
            filePath
          )}' has both .js and .mjs variants, please use one or the other. Using .js by default.`
        )
      }
      return filePathWithJSExtension
    }
  } catch (_) {
    // Do nothing
  }

  // Check if .js variant exists
  try {
    if (require.resolve(filePathWithJSExtension)) {
      return filePathWithJSExtension
    }
  } catch (_) {

View on GitHub (pinned to e85d62f177)

Solutions

  1. Delete one of the two variants (.js or .mjs) so only one resolution exists
  2. Rename one variant to a different base name if both are genuinely needed
  3. Configure your bundler/TS output to emit only one extension
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/gatsby/src/bootstrap/resolve-js-file-path.ts:40 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gatsbyjs/gatsby@e85d62f177 (2026-08-26). Data as JSON: /api/errors/eff877f94b36c698. Report an issue: GitHub.