Webpack 4 + Babel leaving const in transpiled code

若如初见. 提交于 2020-01-03 16:42:58

问题


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)/
      },
   ]

回答1:


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.



来源:https://stackoverflow.com/questions/49508675/webpack-4-babel-leaving-const-in-transpiled-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!