【问题标题】:Safari/Babel/Webpack Const declarations are not supported in strict mode严格模式下不支持 Safari/Babel/Webpack 常量声明
【发布时间】:2015-11-23 19:01:35
【问题描述】:

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

Const declarations are not supported in strict mode.

当我看到失败的线路时,我看到了:

const Crypto = __webpack_require__(624)

这不是我的应用程序中的东西,所以它必须由 Webpack 或其他依赖项注入。

Babel 不应该用var 替换const 吗?

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 中运行。

【问题讨论】:

    标签: safari webpack babeljs


    【解决方案1】:

    您已在 babel-loader 设置中排除了“node_modules”,因此它不会处理您的外部依赖项。你所依赖的这个包可能没有在浏览器中使用测试。

    而且,顺便说一句,babel 不会替换你的常量,除非你使用“transform-es2015-block-scoping”插件。

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

    它不包含在“es2015”预设中。那里只有“check-es2015-constants”插件,它只检查和验证 const 声明。

    将 consts 转换为 vars 的插件称为“transform-es2015-block-scoping”,它包含在“es2015”预设中。

    【讨论】:

    • 根据babeljs.io/docs/plugins/preset-es2015,transform-es2015-block-scoping 插件包含在 es2015 预设中。
    • 任何人都可以为 2018 年的解决方案更新此内容吗?我认为这与my issue 的情况相似,但与es2015 预设的引用似乎不是最新的?
    • 天哪。从昨天开始,我一直在尝试让 babel 编译为 es5。由于您对删除排除 node_modules 设置的回答,我终于解决了这个问题。 ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2018-11-07
    • 2019-09-14
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多