Webpack 4 + Babel将const保留在已转换的代码中 [英] Webpack 4 + Babel leaving const in transpiled code
问题描述
我正在尝试让我的代码在不支持ES6的Android 4.1 Webview上运行.
I'm trying to get my code working on Android 4.1 Webview, which doesn't support ES6.
但是我收到此错误:
未捕获的SyntaxError:在严格模式下使用const.
Uncaught SyntaxError: Use of const in strict mode.
.babelrc配置
{
"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)/
},
]
推荐答案
我发现,问题是由查询字符串"模块引起的,该模块是另一个软件包的依赖项. 如github所述,我明确安装了版本5.然后一切正常.
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.
此模块针对Node.js 6或更高版本以及最新版本的Chrome,Firefox和Safari.如果要支持较旧的浏览器,请使用版本5:npm install query-string @ 5.
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.
这篇关于Webpack 4 + Babel将const保留在已转换的代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!