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

查看:30
本文介绍了严格模式下不支持 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 加载器配置

{
  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 不会替换你的常量.

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

http://babeljs.io/docs/plugins/transform-es2015-块范围/

它不包含在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.

将 consts 转换为 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天全站免登陆