question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:168
  • Comments:31 (6 by maintainers)

github_iconTop GitHub Comments

215reactions
BassemNcommented, Mar 5, 2020

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.

14reactions
vramanacommented, May 27, 2020

@JamesSingleton Upgrading the packages to 7.10 fixed the issue for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No "exports" main resolved in /app/node_modules/@babel ...
I've get error when uploaded netlify, bu run npm install @babel/helper-compilation-targets --save-dev and works . – Diego Santa Cruz Mendezú.
Read more >
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'
The @babel/helper-compilation-targets package works with browsers and Node.js and is used by @babel/preset-env to determine which plugin should be enabled based ...
Read more >
No "exports" main defined - Laracasts
Hello , After cloning my project I got the error bellow when I npm run watch (I deleted the node_modules) ERROR in ./resources/js/app.js...
Read more >
No "exports" main resolved in@babel/helper-compilation ...
Based on @DoubleMalt answer, I downgraded Node to v13.8.0, it worked. It's an old project. However, for the current Nuxt project, it hits...
Read more >
Node.js – Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No ...
Node.js – Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No “exports” main resolved in /app/node_modules/@babel/helper-compilation-targets/package.json.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found