Skip to content

[Bug]: babel-loader not working with node 16.20.1 #15960

@bhargavtenali

Description

@bhargavtenali

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

webpack config

  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              extends: path.join(paths.root, 'tools/config/babel.config.js'),
            },
          },
          {
            loader: 'eslint-loader',
            options: {
              failOnError: true,
              quiet: false,
              fix: true,
              configFile: path.join(paths.root, 'tools/config/.eslintrc.json'),
            },
          },
        ],
        include: [paths.app, paths.admin, paths.suez, paths.styleguide, paths.packages, paths.worldbank],
      },
]

babel-config.js

module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react'],
  plugins: [
    '@babel/plugin-proposal-function-bind',
    '@babel/plugin-proposal-export-default-from',
    '@babel/plugin-proposal-logical-assignment-operators',
    ['@babel/plugin-proposal-optional-chaining', { loose: false }],
    ['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
    ['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
    '@babel/plugin-proposal-do-expressions',
    ['@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-throw-expressions',
    '@babel/plugin-syntax-dynamic-import',
    '@babel/plugin-syntax-import-meta',
    ['@babel/plugin-proposal-class-properties', { loose: false }],
    '@babel/plugin-proposal-json-strings',
  ],
  env: {
    production: {
      plugins: ['transform-react-remove-prop-types'],
    },
  },
}

Configuration file name

babel.config.js

Configuration

module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react'],
  plugins: [
    '@babel/plugin-proposal-function-bind',
    '@babel/plugin-proposal-export-default-from',
    '@babel/plugin-proposal-logical-assignment-operators',
    ['@babel/plugin-proposal-optional-chaining', { loose: false }],
    ['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
    ['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
    '@babel/plugin-proposal-do-expressions',
    ['@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-throw-expressions',
    '@babel/plugin-syntax-dynamic-import',
    '@babel/plugin-syntax-import-meta',
    ['@babel/plugin-proposal-class-properties', { loose: false }],
    '@babel/plugin-proposal-json-strings',
  ],
  env: {
    production: {
      plugins: ['transform-react-remove-prop-types'],
    },
  },
}

Current and expected behavior

Current:
npm run build is failing with node 16.20.1
Getting this error

[WEBPACK] Build failed after 136.829 seconds
[ERROR] => [WEBPACK] Errors building app-3.0.3.js
Module parse failed: 'return' outside of function (4:51)
You may need an appropriate loader to handle this file type.
| 
| if (typeof process === "object" && process.version === "v20.6.0") {
>   if (exports["___internal__alreadyRunning" + ""]) return;
|   Object.defineProperty(exports, "___internal__alreadyRunning", {
|     value: true,
Module parse failed: 'return' outside of function (4:51)
You may need an appropriate loader to handle this file type.
| 
| if (typeof process === "object" && process.version === "v20.6.0") {
>   if (exports["___internal__alreadyRunning" + ""]) return;
|   Object.defineProperty(exports, "___internal__alreadyRunning", {
|     value: true,
[ERROR] =>  Build failure..

It is working fine with node 14

Environment

  • Babel 7.4.3
  • webpack 4.29.6
  • node 16.20.1
  • npm 8.19.4

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: third partyoutdatedA 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