Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel 7 doesn't change CONST to VAR

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
    ]
};
like image 398
olga_babic Avatar asked Sep 17 '18 07:09

olga_babic


Video Answer


1 Answers

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"],
  }
}]
like image 121
Hitmands Avatar answered Sep 24 '22 13:09

Hitmands