webpack 5 with babel not transpiling to node 0.12 (es5.1)

I’ve a node.js app that is using webpack and babel to transpile to node.js 8.x, I’m trying to get it to transpile to the much older node.js 0.12 to support some older devices, but for some reason the output bundle just looks like regular node8 code with arrow functions and template literals (among other es6 features).

Below are webpack.config.js, .babelrc and package.json, I’ve been trying anything I can think of to try and get it to work so they are bloated with some stuff that’s probably not required.

webpack.config.js (the relevant part):

module.exports = {
    mode: 'production',
    cache: false,
    target: ['es5', 'node0.12'],
    entry: ['./index.js', 'core-js/stable', 'regenerator-runtime/runtime'],
    output: {
        path: path.resolve(__dirname, 'build/'),
        filename: 'index.js',
    },
    resolve: {
        modules: ['node_modules',
            conf.NPM_LOCAL+'/lib/node_modules/',
        ],
        alias: {
            '/util': '../util',
        },
        mainFields: ['main', 'module'],
    },
    module: {
        rules: [{
            test: /.json$/,
            exclude: /(node_modules|race_lib[\/]node_modules|build)/,
            use: 'json-loader',
            type: 'javascript/auto',
        }, {
            test: /.js$/,
            exclude: /(node_modules|race_lib[\/]node_modules|build)/,
            use: [{
                loader: 'babel-loader',
                options: {
                    presets: ['@babel/preset-env', {
                        targets: {
                            node: '0.12'
                        },
                        useBuiltIns: 'usage',
                        corejs: 3,
                        debug: true,
                    }],
                    plugins: [
                        '@babel/plugin-transform-runtime',
                        '@babel/plugin-transform-arrow-functions',
                        '@babel/plugin-transform-template-literals',
                        '@babel/plugin-transform-block-scoping',
                        '@babel/plugin-transform-parameters',
                        '@babel/plugin-transform-destructuring',
                        '@babel/plugin-transform-spread',
                        '@babel/plugin-transform-shorthand-properties',
                    ],
                    sourceType: 'unambiguous',
                },
            }],
        }, {
            test: /race_lib[\/]util[\/].+.js$/,
            use: [{
                loader: 'imports-loader',
                options: {
                    type: 'commonjs',
                    imports: ['single util node_util'],
                    additionalCode: 'var is_node = true, is_rn = false, worker_threads = {isMainThread: true};',
                },
            }],
        }, {
            test: /race_lib[\/]util[\/]config.js$/,
            use: [{
                loader: 'imports-loader',
                options: {
                    type: 'commonjs',
                    imports: 'pure fs.promises',
                },
            }],
        }, {
            test: /race_lib[\/]node_modules[\/].+[\/]index.js$/,
            use: path.resolve(__dirname, 'fs_promises_fixup.js')
        }, {
            test: /node_modules[\/].+.(js|jsx|mjs)$/,
            exclude: /node_modules[\/]@babel[\/]runtime/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: ['@babel/preset-env'],
                    plugins: [
                        'babel-plugin-transform-globalthis',
                        '@babel/plugin-transform-arrow-functions',
                        '@babel/plugin-transform-template-literals',
                        '@babel/plugin-transform-block-scoping',
                        '@babel/plugin-transform-parameters',
                        '@babel/plugin-transform-destructuring',
                        '@babel/plugin-transform-spread',
                        '@babel/plugin-transform-shorthand-properties',
                    ],
                },
            },
        }],
    },
    stats: {
        errorDetails: true
    },
    externals: [function (_ref, cb) {
        var request = _ref.request;
        if (request.startsWith('node:')) return cb(null, "commonjs ".concat(request.slice(5)));
        cb();
  }, {
    ...
  }],
};

.babelrc:

{
    "presets": [
        ["@babel/preset-env", {
            "targets": {
                "node": "0.12"
            },
            "useBuiltIns": "usage",
            "corejs": 3,
            "debug": true
        }]
    ],
    "plugins": [
        ["@babel/plugin-transform-runtime", {
            "regenerator": true
        }],
        "@babel/plugin-transform-regenerator",
        "babel-plugin-transform-globalthis",
        "@babel/plugin-transform-arrow-functions",
        "@babel/plugin-transform-template-literals",
        "@babel/plugin-transform-block-scoping",
        "@babel/plugin-transform-parameters",
        "@babel/plugin-transform-destructuring",
        "@babel/plugin-transform-spread",
        "@babel/plugin-transform-shorthand-properties"
    ],
    "sourceType": "unambiguous"
}

package.json:

{
    "author": "xxx",
    "dependencies": {
        "@babel/runtime": "7.24.5",
        "core-js": "3.37.1",
        "fs.promises": "0.1.2",
        "regenerator-runtime": "0.14.1"
    },
    "description": "xxx",
    "devDependencies": {
        "@babel/core": "7.24.5",
        "@babel/node": "7.23.9",
        "@babel/plugin-transform-arrow-functions": "^7.24.7",
        "@babel/plugin-transform-block-scoping": "^7.24.7",
        "@babel/plugin-transform-destructuring": "^7.24.8",
        "@babel/plugin-transform-parameters": "^7.24.7",
        "@babel/plugin-transform-regenerator": "7.24.7",
        "@babel/plugin-transform-runtime": "7.24.7",
        "@babel/plugin-transform-shorthand-properties": "^7.24.7",
        "@babel/plugin-transform-spread": "^7.24.7",
        "@babel/plugin-transform-template-literals": "^7.24.7",
        "@babel/preset-env": "7.24.5",
        "amd-to-commonjs-codemod": "^1.2.0",
        "babel-loader": "9.1.3",
        "babel-plugin-transform-globalthis": "1.0.0",
        "imports-loader": "^5.0.0",
        "jscodeshift": "^0.16.1",
        "terser-webpack-plugin": "5.3.10",
        "webpack-cli": "5.1.4",
        "webpack-merge": "5.10.0"
    },
    "license": "xxx",
    "main": "index.js",
    "name": "com.myapp",
    "scripts": {
        "build": "webpack --env development",
        "build_prod": "webpack --env production",
        "clean": "rm -fr build"
    },
    "version": "x.x.x"
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật