Skip to content

No "exports" main resolved in @babel/helper-compilation-targets/package.json #11216

Closed

Description

@Drogglbecher

Bug Report

Current Behavior
Since an update to node 13.10.1 I have a problem while building an application with babel-loader:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in node_modules/@babel/helper-compilation-targets/package.json

Expected behavior/code
It should build correctly

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

  • Filename: babel.config.js
const baseConfig = {
  presets: [
    [
      '@babel/preset-env',
      {
        useBuiltIns: 'entry',
        corejs: 3,
      },
    ],
    '@babel/preset-react',
    '@babel/preset-flow',
    '@babel/preset-typescript',
  ],
  plugins: [
    'react-hot-loader/babel',
    'babel-plugin-styled-components',
    ['@babel/plugin-proposal-class-properties', { loose: true }],
    '@babel/plugin-syntax-dynamic-import',
    isTesting && 'babel-plugin-dynamic-import-node-babel-7',
  ].filter(Boolean),
};

module.exports = {
  sourceType: 'unambiguous',
  ...baseConfig,
  plugins: [
    'idx',
    '@babel/plugin-syntax-import-meta',
    '@babel/plugin-proposal-json-strings',
    [
      '@babel/plugin-proposal-decorators',
      {
        legacy: true,
      },
    ],
    '@babel/plugin-proposal-function-sent',
    '@babel/plugin-proposal-export-namespace-from',
    '@babel/plugin-proposal-numeric-separator',
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-throw-expressions',
    'babel-plugin-macros',
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        root: ['./'],
        alias: {
          'react-router-dom': './packages/components/Router',
          '@@react-router-dom': './node_modules/react-router-dom',
        },
      },
    ],
  ],
  env: {
    test: {
      plugins: [
        ...baseConfig.plugins,
        '@babel/plugin-transform-modules-commonjs',
      ],
    },
  },
};

Environment

  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 13.10.1 - /usr/local/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.14.2 - /usr/local/bin/npm
  Monorepos:
    Yarn Workspaces: 1.22.0
  npmPackages:
    @babel/core: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-class-properties: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-decorators: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-export-namespace-from: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-function-sent: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-json-strings: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-numeric-separator: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-optional-chaining: ^7.8.3 => 7.8.3
    @babel/plugin-proposal-throw-expressions: ^7.8.3 => 7.8.3
    @babel/plugin-syntax-dynamic-import: ^7.8.3 => 7.8.3
    @babel/plugin-syntax-import-meta: ^7.8.3 => 7.8.3
    @babel/preset-env: ^7.8.3 => 7.8.3
    @babel/preset-flow: ^7.8.3 => 7.8.3
    @babel/preset-react: ^7.8.3 => 7.8.3
    @babel/preset-typescript: ^7.8.3 => 7.8.3
    babel-eslint: ^10.0.3 => 10.0.3
    babel-loader: ^8.0.6 => 8.0.6
    babel-plugin-idx: ^2.4.0 => 2.4.0
    babel-plugin-lodash: ^3.3.4 => 3.3.4
    babel-plugin-macros: ^2.8.0 => 2.8.0
    babel-plugin-module-resolver: ^4.0.0 => 4.0.0
    babel-plugin-styled-components: ^1.10.7 => 1.10.7
    eslint: ^6.8.0 => 6.8.0
    jest: ^25.1.0 => 25.1.0
    webpack: ^4.41.5 => 4.41.5

Possible Solution
snowpack resolved the error like this. Maybe this could work here too.


Edits by @JLHwung

Solution

If you hit this issue from search engines, please update all @babel deps to v7.8.7 or above.

Activity

  1. babel-bot commented on Mar 5, 2020

    @babel-bot
    Collaborator

    Hey @Drogglbecher! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

    If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

  2. JLHwung commented on Mar 5, 2020

    @JLHwung
    Contributor

    I can not reproduce this error on my local environments (macOS + Node.js 13.10.1). However I do notice that if package.json/exports/ is changed to something like

    "exports": {
        "foo": "./lib/index.js"
      },
    

    It will throw exactly the same error as you posted. Can you check if the node_modules/@babel/helper-compilation-targets/package.json is same as https://unpkg.com/browse/@babel/helper-compilation-targets@7.8.7/package.json ?

  3. Drogglbecher commented on Mar 5, 2020

    @Drogglbecher
    Author

    Ah, ok, in version 7.8.3 of babel we have

    {
      "name": "@babel/helper-compilation-targets",
      "version": "7.8.3",
      "author": "The Babel Team (https://babeljs.io/team)",
      "license": "MIT",
      "description": "Engine compat data used in @babel/preset-env",
      "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-compilation-targets",
      "main": "lib/index.js",
      "exports": false,
      "publishConfig": {
        "access": "public"
      },
      "keywords": [
        "babel",
        "babel-plugin"
      ],
      "dependencies": {
        "@babel/compat-data": "^7.8.1",
        "browserslist": "^4.8.2",
        "invariant": "^2.2.4",
        "levenary": "^1.1.0",
        "semver": "^5.5.0"
      },
      "peerDependencies": {
        "@babel/core": "^7.0.0"
      },
      "devDependencies": {
        "@babel/core": "^7.8.3",
        "@babel/helper-plugin-test-runner": "^7.8.3"
      },
      "gitHead": "a7620bd266ae1345975767bbc7abf09034437017"
    }
    

    The exports: false could be the thing here.

  4. nicolo-ribaudo commented on Mar 5, 2020

    @nicolo-ribaudo
    Member

    Yeah, we fixed it in 7.8.4. Although, exports: false should work starting with Node 13.2 🤔 (The fix was for Node 13.1-13.2)

  5. JLHwung commented on Mar 5, 2020

    @JLHwung
    Contributor

    Let the issue stay open for a while as people upgrading to latest node with babel 7.8.3 will be constantly bothered by this issue. I have also filed an issue on node.js: nodejs/node#32107

  6. BassemN commented on Mar 5, 2020

    @BassemN

    I'm getting the same error after updating to node v13.10.1 so I switched back to node LTS v12.16.1 and the error gone. I hope this issue fixed soon.

  7. BassemN commented on Mar 5, 2020

    @BassemN

    I fixed this issue by removing the node_modules directory and package-lock.json file then run npm install to fresh install all packages then the issue was fixed.

  8. mluce194 commented on Mar 10, 2020

    @mluce194

    I had this issue when trying to run gatsby develop. I tried doing some of the things listed above but nothing worked.

  9. nicolo-ribaudo commented on Mar 10, 2020

    @nicolo-ribaudo
    Member

    What is your @babel/helper-compilation-targets version?

  10. mluce194 commented on Mar 10, 2020

    @mluce194

    It is 7.8.3

  11. 71 remaining items

  12. bupy7 commented on Oct 16, 2020

    @bupy7

    I just have upgraded @babel/ packages, removed node_modules and reinstalled its. After everything is ok.

    NodeJS: v12.19.0

  13. amkayondo commented on Dec 6, 2020

    @amkayondo

    I fixed this issue by removing the node_modules directory and package-lock.json file then run npm install to fresh install all packages then the issue was fixed.

    This worked for me

  14. added a commit that references this issue on Jan 9, 2021
  15. added
    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue
    on Mar 8, 2021
  16. locked as resolved and limited conversation to collaborators on Mar 8, 2021
  17. added a commit that references this issue on Nov 17, 2022
    b9ebc73
  18. added a commit that references this issue on Oct 4, 2025
    5013b30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: upstreamoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions