No “exports” main resolved in @babel/helper-compilation-targets/package.json with Node 12.17.0

Bug Report

I know #11216 mentions a similar issue, but that is with Node 13, this is with the newly released 12.17.0.

Current behavior

Node just released 12.17.0 and now running "build": "babel src -d ./", with the following deps (also installed the latest versions as well and still had the issue)

"@babel/cli": "^7.8.3",
"@babel/core": "^7.8.3",

results in:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /Users/singleton/OSS/holocron/node_modules/@babel/helper-compilation-targets/package.json
    at applyExports (internal/modules/cjs/loader.js:491:9)
    at resolveExports (internal/modules/cjs/loader.js:507:23)
    at Function.Module._findPath (internal/modules/cjs/loader.js:635:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:953:27)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/singleton/OSS/holocron/node_modules/@babel/preset-env/lib/debug.js:8:33)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Input Code

"build": "babel src -d ./",

Expected behavior

It should build properly without error as it does on Node 12.16.3.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = function (api) {
  api.cache(true);
  return {
    babelrcRoots: ['.', './packages/*'],
  };
}

Environment

System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node
    npm: 6.14.4 - ~/.nvm/versions/node/v12.17.0/bin/npm
  Monorepos:
    Lerna: 3.20.2
  npmPackages:
    @babel/cli: ^7.8.3 => 7.8.3 
    @babel/core: ^7.8.3 => 7.8.3 
    babel-preset-amex: ^2.1.0 => 2.2.0 
    eslint: ^6.8.0 => 6.8.0 
    jest: ^25.1.0 => 25.1.0 
    lerna: ^3.20.2 => 3.20.2 

Additional context
It works fine on Node 12.16.3.

3 thoughts on “No “exports” main resolved in @babel/helper-compilation-targets/package.json with Node 12.17.0

  1. In my case, the @babel/helper-compilation-targets package is installed as a dependency of @babel/preset-env. Updating it to the latest version fixed the issue for me.

    $ npm ls @babel/helper-compilation-targets
    └─┬ @babel/preset-env@7.8.3
      └── @babel/helper-compilation-targets@7.8.3