'@capacitor-community/http plugin import bundled with webpack throws SyntaxError in Android Studio

I am importing @capacitor-community/http plugin in a .js file:

import { Http } from '@capacitor-community/http';

which is then bundled with webpack into a library (pages.bundle.js), using this in webpack.config.js:

 module.exports = [
  {
    mode: "production",
    entry: "./src/index.js",
    output: {
      path: path.resolve(__dirname, "www/js/"),
      filename: "index.bundle.js"
    }
  },
  {
    mode: "production",
    entry: "./src/pages.js",
    output: {
      path: path.resolve(__dirname, "www/js/"),
      filename: "pages.bundle.js",
      library: {
        name: "myutilities",
        type: 'umd',
      }
    },
    resolve: {
      fallback: {
        util: require.resolve("util/")
      }
    },
    plugins: [
      new webpack.ProvidePlugin({
        process: 'process/browser',
      }),
    ]
  }
];

The bundled script is brought into the page using a script tag, and this works fine in Xcode/iOS Simulator, but throws a SyntaxError in Android Studio:

File: http://localhost/js/pages.bundle.js - Line 2 - Msg: Uncaught SyntaxError: Unexpected token (

If I remove/comment-out this specific import statement, the error goes away. Any ideas, why this might be happening?

These are the dependencies in package.json:

  "dependencies": {
    "@capacitor-community/http": "^1.4.1",
    "@capacitor/android": "^3.5.0",
    "@capacitor/camera": "latest",
    "@capacitor/core": "latest",
    "@capacitor/device": "^1.1.2",
    "@capacitor/ios": "^3.5.0",
    "@capacitor/splash-screen": "latest",
    "handlebars-helpers": "^0.10.0",
    "handlebars-utils": "^1.0.6",
    "process": "^0.11.10",
    "util": "^0.12.4"   },
  "devDependencies": {
    "@capacitor/cli": "latest",
    "webpack": "^5.72.0",
    "webpack-cli": "^4.9.2"
  },


Solution 1:[1]

This problem seems to be rooted in compatibility with older devices. It occurs when I select Nexus 5X API 24, which is what I was testing with initially. When I switched to Pixel 3 API 30 or Pixel 4 API 30, it does not show.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BAHasan