严格模式下不支持Safari/Babel/Webpack Const声明 [英] Safari/Babel/Webpack Const declarations are not supported in strict mode

查看:174
本文介绍了严格模式下不支持Safari/Babel/Webpack Const声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Safari无法通过此行加载我的React应用程序:

Safari is failing to load my React app with this line:

Const declarations are not supported in strict mode.

当我查看失败的行时,我看到的是:

When I look at the line that's failing I'm seeing:

const Crypto = __webpack_require__(624)

这不是我的应用程序中的内容,因此必须由Webpack或其他依赖项注入.

This isn't something in my app so it must be injected by Webpack or another dependency.

Babel不能用var代替const吗?

Shouldn't Babel replace const with var?

Babel依赖关系

"babel": "~6.1.0",
"babel-core": "~6.2.0",
"babel-loader": "~6.2.0",
"babel-plugin-transform-runtime": "~6.1.0",
"babel-polyfill": "~6.2.0",
"babel-preset-es2015": "~6.1.0",
"babel-preset-react": "~6.1.0",
"babel-preset-stage-0": "~6.1.0",
"babel-runtime": "~6.2.0"

Babel Loader配置

{
  test: /\.js|\.jsx$/,
  exclude: /node_modules/,
  loader: 'babel-loader',
  query: {
    cacheDirectory: true,
    plugins: ['transform-runtime'],
    presets: ['es2015', 'react', 'stage-0']
  }
}

注意,我的应用程序可以在Chrome浏览器中运行.

NOTE My app does work in Chrome.

推荐答案

您已在babel-loader设置中排除了"node_modules",因此它不会处理您的外部依赖项.您所依赖的这个程序包可能未经过浏览器内部使用的测试.

You've excluded "node_modules" in babel-loader settings, so it doesn't process your external dependencies. This package you depend on probably is not tested for in-browser usage.

而且,顺便说一句,除非您使用"transform-es2015-block-scoping"插件,否则babel仍然不会替换您的consts.

And, btw, babel won't replace your consts anyway unless you use "transform-es2015-block-scoping" plugin.

http://babeljs.io/docs/plugins/transform-es2015 -block-scoping/

"es2015"预设中未包含该内容.那里只有一个"check-es2015-constants"插件,该插件仅检查和验证const声明.

It's not included in "es2015" preset. There you have only "check-es2015-constants" plugin which just checks and validates const declarations.

将const转换为vars的插件称为"transform-es2015-block-scoping",并且包含在"es2015"预设中.

The plugin which transforms consts into vars is called "transform-es2015-block-scoping" and it's included in "es2015" preset.

这篇关于严格模式下不支持Safari/Babel/Webpack Const声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆