首页 > 解决方案 > TypeError: Attempting to change enumerable attribute of unconfigurable property (Vue.js SPA)(Webpack 4)(iPhone 6S)(iOS Safari)

问题描述

(2018-7-29)

1. 背景(技术栈)

2.问题

在 iOS Safari 中访问我的网站,
出现白屏(因为 JS 错误,所以没有渲染)

3. 截图

在此处输入图像描述 在此处输入图像描述

放大错误信息

在此处输入图像描述

3.错误信息

TypeError:尝试更改不可配置属性的可枚举属性。

4.如何重现?

  1. 访问https://browserstack.com
  2. 选择 iPhone 6S Safari
  3. 访问https://wittcism.com

3. 我的配置

/webpack.config.js

var path = require('path')
var webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin'); // https://github.com/webpack-contrib/copy-webpack-plugin

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js',
  },
  module: {
    rules: [{
        test: /\.md$/,
        use: 'raw-loader'
      },
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },
      {
        test: /\.scss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader'
        ],
      },
      {
        test: /\.sass$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader?indentedSyntax'
        ],
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            'scss': [
              'vue-style-loader',
              'css-loader',
              'sass-loader'
            ],
            'sass': [
              'vue-style-loader',
              'css-loader',
              'sass-loader?indentedSyntax'
            ]
          }
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: { minify: true }
          }
        ]
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': path.resolve(__dirname, './src/'),
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.output = {
      path: path.resolve(__dirname, './dist'),
      publicPath: '/dist/',
      filename: '[name].[hash].js',
    },
    module.exports.plugins = (module.exports.plugins || []).concat([
      new webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: '"production"'
        }
      }),
      new webpack.LoaderOptionsPlugin({
        minimize: true
      }),
      new CleanWebpackPlugin(['dist']),
      new HtmlWebpackPlugin({
        title: 'Wittcism',
        filename: './index.html',
        template: './template/index.html',
        minify: true,
      }),
    ])
}

.babelrc

{
  "presets": [
    ["env", { "modules": false }],
    "stage-3"
  ]
}

包.json

{
  "name": "hide",
  "description": "hide",
  "version": "1.1.0",
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot --port 8081 --host 0.0.0.0",
    "build": "cross-env NODE_ENV=production webpack --mode production --progress --hide-modules"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "babel-polyfill": "^6.26.0",
    "bootstrap": "^4.1.1",
    "bootstrap-vue": "^2.0.0-rc.11",
    "es6-promise": "^4.2.4",
    "jstransformer-verbatim": "^1.1.1",
    "jwt-decode": "^2.2.0",
    "moment": "^2.22.2",
    "qiniu-js": "^2.4.0",
    "tippy.js": "^2.5.4",
    "tui-editor": "^1.2.3",
    "v-tooltip": "^2.0.0-rc.33",
    "vue": "^2.5.11",
    "vue-carousel": "^0.10.0",
    "vue-i18n": "^8.0.0",
    "vue-markdown": "^2.2.4",
    "vue-router": "^3.0.1",
    "vuelidate": "^0.7.4",
    "vuex": "^3.0.1"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "ie 6-8"
  ],
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-3": "^6.24.1",
    "clean-webpack-plugin": "^0.1.19",
    "copy-webpack-plugin": "^4.5.2",
    "cross-env": "^5.0.5",
    "css-loader": "^0.28.7",
    "file-loader": "^1.1.4",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.9.0",
    "pug": "^2.0.3",
    "pug-loader": "^2.4.0",
    "raw-loader": "^0.5.1",
    "sass-loader": "^6.0.7",
    "style-loader": "^0.21.0",
    "vue-loader": "^14.2.2",
    "vue-template-compiler": "^2.4.4",
    "webpack": "^4.16.3",
    "webpack-bundle-analyzer": "^2.13.1",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^2.9.1"
  }
}

问题:如何解决:TypeError: Attempting to change enumerable attribute of unconfigurable property?

我的猜测:iOS Safari 不完全支持 ES6

标签: javascriptwebpackvue.jsecmascript-6safari

解决方案


推荐阅读