简体   繁体   中英

Consts still in bundle even though using babel env preset safari >= 7

I have a client that has employees working on older iPads and they can't update their safari versions to 10.x+ so they're stuck w/ safari 9.x. And I keep getting the following error when I try to load my browser app in Safari 9.x on an iPad:

SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

I'm using babel-loader in my webpack config and I have the following babel options that I'm setting on the loader's options property:

 { presets: [ [ "env", { targets: { browsers: ["last 3 versions", "safari >= 8"] }, debug: true } ], // `es2015`, `stage-1` ], retainLines: true, plugins: [ "syntax-jsx", "transform-react-jsx", "transform-react-display-name", "transform-react-require", "transform-es2015-destructuring", "transform-es2015-parameters", "transform-object-rest-spread", "transform-class-properties", // "check-es2015-constants", // "transform-es2015-block-scoping", ["transform-runtime", { "polyfill": false, "regenerator": true }] ] } 

In my console when I do the build, it EVEN SAYS:

Using targets:
{
  "chrome": "59",
  "android": "4.4",
  "edge": "13",
  "firefox": "54",
  "ie": "9",
  "ios": "10",
  "safari": "8"
}

And:

Using plugins:
  check-es2015-constants {"android":"4.4","edge":"13","ie":"9","safari":"8"}
  transform-es2015-block-scoping {"android":"4.4","edge":"13","ie":"9","safari":"8"}

But there are STILL const declarations (65 to be exact) throughout my bundle. And no, they aren't all node_module imports... Most are my own React component files.

How do I get babel to just replace ALL instances of const w/ var ?

I'm on webpack 3.7.1 and babel-loader 7.1.2 and babel-core 6.26

Turns out I was using a Webpack alias for this project still: https://github.com/njl07/rx-http-request/issues/15#issue-273561398

Apparently babel transformations aren't applied to aliases for some reason.

Updated to the latest package and all is good now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM