Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack 4 + Babel leaving const in transpiled code

I'm trying to get my code working on Android 4.1 Webview, which doesn't support ES6.

But I am getting this error:

Uncaught SyntaxError: Use of const in strict mode.

.babelrc config

{
  "plugins": [
    "lodash"
  ],
  "presets": [
    "@babel/preset-react",
    [
      "@babel/preset-env",
      {
        "targets": {
          "android": "4.1"
        },
        "useBuiltIns": "usage",
        "forceAllTransforms": true
      }
    ],
    "@babel/preset-stage-0"
  ]
}

webpack.config.js

rules: [
      {
        enforce: 'pre',
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: "eslint-loader"
      },
      {
        test: /\.jsx?$/,
        loaders: 'babel-loader',
        options: {
          plugins: ['lodash']
        },
        exclude: /(node_modules|bower_components)/
      },
   ]
like image 408
btx Avatar asked Mar 27 '18 09:03

btx


1 Answers

I figured out, that the issue was caused by the "query-string" module, which is a dependency of another package. As described on github, i installed version 5 explicitly. Then everything worked well.

Github: query-string

This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers, use version 5: npm install query-string@5.

like image 129
btx Avatar answered Jan 03 '23 07:01

btx