babel/babel · error · Error

commonJS() requires import.meta.url

Error message

commonJS() requires import.meta.url

What it means

Error "commonJS() requires import.meta.url" thrown in babel/babel.

Source

Thrown at scripts/repo-utils/index.cjs:61

  exports.describeBabel9 = bool(process.env.BABEL_9_BREAKING)
    ? describe
    : dummy;
  exports.describeGte = function (version) {
    return semver.gte(process.version, version) ? describe : describe.skip;
  };
  exports.describeSatisfies = function (version) {
    return semver.satisfies(process.version, version)
      ? describe
      : describe.skip;
  };
  exports.describeNoCITGM = __dirname.includes("citgm_tmp")
    ? describe.skip
    : describe;
}

exports.commonJS = function (metaUrl) {
  if (!metaUrl) {
    throw new Error("commonJS() requires import.meta.url");
  }
  const filename = fileURLToPath(metaUrl);
  const dirname = path.dirname(filename);
  return {
    __filename: filename,
    __dirname: dirname,
    // Only available in Node.js 12+
    require: createRequire ? createRequire(filename) : null,
  };
};

View on GitHub (pinned to 06b6eae39d)

Solutions

  1. Pass import.meta.url when calling commonJS(): require('@babel/repo-utils').commonJS(import.meta.url).
  2. From a .cjs file, pass the caller module's URL explicitly since this shim cannot infer it.

Example fix

const { __dirname, require } = commonJS(import.meta.url);

When it happens

Trigger: Thrown at scripts/repo-utils/index.cjs:61 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03). Data as JSON: /data/errors/a357a36191b93da0.json. Report an issue: GitHub.