@babel/runtime 7.13.3 unexpected cjs modules in esm modules

Bug Report

  • I would like to work on a fix!

Current behavior

https://unpkg.com/@babel/runtime@7.13.2/helpers/createSuper/_index.mjs

import getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import isNativeReflectConstruct from "@babel/runtime/helpers/isNativeReflectConstruct";
import possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
export default function _createSuper(Derived) {
  var hasNativeReflectConstruct = isNativeReflectConstruct();
  return function _createSuperInternal() {
    var Super = getPrototypeOf(Derived),
        result;

    if (hasNativeReflectConstruct) {
      var NewTarget = getPrototypeOf(this).constructor;
      result = Reflect.construct(Super, arguments, NewTarget);
    } else {
      result = Super.apply(this, arguments);
    }

    return possibleConstructorReturn(this, result);
  };
}

Expected behavior

Should it be?

```js
- import getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
- import isNativeReflectConstruct from "@babel/runtime/helpers/isNativeReflectConstruct";
- import possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
+ import getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
+ import isNativeReflectConstruct from "@babel/runtime/helpers/esm/isNativeReflectConstruct";
+ import possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
export default function _createSuper(Derived) {
  var hasNativeReflectConstruct = isNativeReflectConstruct();
  return function _createSuperInternal() {
    var Super = getPrototypeOf(Derived),
        result;

    if (hasNativeReflectConstruct) {
      var NewTarget = getPrototypeOf(this).constructor;
      result = Reflect.construct(Super, arguments, NewTarget);
    } else {
      result = Super.apply(this, arguments);
    }

    return possibleConstructorReturn(this, result);
  };
}

like: https://unpkg.com/browse/@babel/runtime@7.12.0/helpers/esm/createSuper.js

Environment

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 15.3.0 - ~/.nvm/versions/node/v15.3.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v15.3.0/bin/yarn
    npm: 7.0.14 - ~/.nvm/versions/node/v15.3.0/bin/npm
  npmPackages:
    @babel/runtime: ^7.12.5 => 7.13.2 
    babel-plugin-add-react-displayname: ^0.0.5 => 0.0.5 
    eslint: ^7.9.0 => 7.20.0 
    eslint-plugin-babel: ^5.3.0 => 5.3.1 
    jest: ^26.0.0 => 26.6.3 
  • Babel version(s): 7.13.3
  • Node/npm version: 15.3.0
  • OS: [e.g. macOS 10.15.4, Windows 10]
  • Monorepo: [e.g. yes/no/Lerna]
  • How you are using Babel: [e.g. webpack, rollup, parcel, babel-register]

Possible Solution

Additional context

2 thoughts on “@babel/runtime 7.13.3 unexpected cjs modules in esm modules

  1. Is this causing a problem? @babel/runtime/helpers/getPrototypeOf should resolve to _index.mjs in every tool that supports Node.js’s resolution algorithm, and in the worst case the CJS version should still work.