简体   繁体   中英

const and let not working in Safari 9.x, is this a transpiler issue?

The app I'm working on is having issues running on Safari (it runs fine everywhere else). There, it doesn't load my bundle.js file and spits out a error message saying 'unexpected use of reserved word 'let' in strict mode.

I've seen from a few other questions that this is most likely due to a transpiler issue - but I'm not an expert in Webpack or Babel and I don't know where to start to fix this.

Here is my webpack config (common) file:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: ['babel-polyfill', path.join(__dirname, `/src/main.js`)],
  output: {
    path: path.join(__dirname, `/public`),
    filename: `bundle.js`
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [
          path.join(__dirname, '/node_modules'),
        ],
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react'],
            plugins: [
              ['transform-class-properties', { 'spec': true }],
              ['transform-object-rest-spread']
            ]
          }
        }
      }, {
        test: /\.s?css$/,
        use: [
          { loader: 'style-loader' },
          { loader: 'css-loader' },
          { loader: 'sass-loader' }
        ]
      }
    ]
  }
};

and here is my package.json:

{
  "name": "last-minute",
  "version": "1.0.0",
  "description": "connect to others nearby for last-minute hanging out",
  "main": "webpack.prod.js",
  "engines": {
    "node": "9.5.0",
    "npm": "6.1.0"
  },
  "scripts": {
    "test": "jest --config jest.config.json",
    "start": "node server/server.js",
    "build": "webpack --config webpack.prod.js",
    "dev": "webpack --config webpack.dev.js --mode development && node server/server.js",
    "light": "webpack --config webpack.light.js --mode development && node light-server/style-server.js"
  },
  "author": "Doug Sauve",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.0.0-beta.44",
    "@babel/preset-env": "^7.0.0-beta.44",
    "@babel/preset-react": "^7.0.0-beta.44",
    "@google/maps": "^0.4.6",
    "babel-loader": "^8.0.0-beta.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "bcryptjs": "^2.4.3",
    "css-loader": "^0.28.11",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "express": "^4.16.2",
    "google-maps-react": "^2.0.2",
    "jest": "^22.4.4",
    "moment": "^2.22.1",
    "mongoose": "^5.0.14",
    "node-sass": "^4.9.2",
    "nodemailer": "^4.6.5",
    "normalize.css": "^8.0.0",
    "raf": "^3.4.0",
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-geocode": "0.0.9",
    "react-redux": "^5.0.7",
    "react-test-renderer": "^16.0.0",
    "redux": "^4.0.0",
    "sass-loader": "^6.0.7",
    "socket.io": "^2.1.0",
    "style-loader": "^0.20.3",
    "validator": "^10.2.0",
    "webpack": "^4.4.1",
    "webpack-cli": "^2.0.13",
    "webpack-merge": "^4.1.2"
  }
}

Safari 9 不支持 ES6 'let'。 Can I Use是用于检查浏览器兼容性的相当好的资源。

Untested possibility: I will be testing this later, but if you haven't solved this yet, check your .babelrc file

I was trying to solve a compatibility issue with polyfill today and it may be because I did not configure my preset environment properly for older versions of iOS. This page in Babel shows you how to configure your presets for Safari versions 7 or greater:

https://babeljs.io/docs/en/6.26.3/babel-preset-env

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