15
votes

I have problem with Safari version <= 9. Babel doesn't seem to replace const with var.

I get this error in console:

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

I tried using @babel/preset-stage-0 but babel removed it.

This is my app configuration:

.babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-transform-object-assign"
  ]
}

webpack.config.js

const path = require("path");
const webpack = require("webpack");
const componentName = "contact-captain";
const publicFolderRelativePath = "../../../../public/js";
const ignorePlugin = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);


module.exports = {
    // devtool: "source-map",
    output: {
        path: path.resolve(__dirname, publicFolderRelativePath),
        filename: `${componentName}.js`
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            }
        ]
    },
    plugins: [
        ignorePlugin
    ]
};
1
Cao Olga. What do you mean by "@babel/preset-stage-0 but babel removed it"?Lazar Nikolic
When I try to build my project I get this error: we've removed Babel's Stage presets. Please consider reading our blog post on this decision at babeljs.io/blog/2018/07/27/removing-babels-stage-presets I'm not sure what to use insteadolga_babic
Ok. Didn't know. Thanx!Lazar Nikolic
I have the same problem. Whatever config in .babelrc I set, it doesn't work...zzzgoo

1 Answers

1
votes

did you try to configure preset-env ? you can find the browsers list here: https://github.com/browserslist/browserslist

probably need to add Safari 8 in your list...

["@babel/preset-env", {
  "targets": {
    "browsers": ["last 2 versions"],
  }
}]