无法在我的vuejs项目中使用for..of

时间:2017-11-01 07:30:13

标签: javascript webpack ecmascript-6 babel

当我在项目中使用for..of时,我收到以下错误:

for...of statements are not supported. Use `transforms: { forOf: false }` to skip transformation and disable this error, or `transforms: { dangerousForOf: true }` if you know what you're doing (24:8)

我不明白我在哪里必须添加这个transform语句。我甚至不明白为什么它不会让我使用基本的ES6功能。

是webpack吗?通天塔?我在哪里添加此声明?

我的.babelrc

{
  "presets": [
    ["es2015", { "modules": false }]
  ]
}

webpack.config.js:

// vim: set expandtab tabstop=2 :

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

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  resolve: {
    alias: {
      'public': path.resolve(__dirname, './public')
    }
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          preLoaders: {
            i18n: 'yaml-loader'
          },
          loaders: {
            i18n: '@kazupon/vue-i18n-loader'
          }
        }
      },
      {
        test: /\.js$/,
        loader: 'buble-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.styl$/,
        loader: ['style-loader', 'css-loader', 'stylus-loader']
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)$/,
        loader: 'file-loader?name=public/fonts/[name].[ext]'
      }
    ]
  }

.eslintrc.js:

module.exports = {
  root: true,
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'module'
  },
  env: {
    browser: true,
  },
  extends: 'airbnb-base',
  // required to lint *.vue files
  plugins: [
    'html'
  ],
  // check if imports actually resolve
  'settings': {
    'import/resolver': {
      'webpack': {
        'config': 'webpack.config.js'
      }
    }
  },
  // add your custom rules here
  'rules': {
    // don't require .vue extension when importing
    'import/extensions': ['error', 'always', {
      'js': 'never',
      'vue': 'never'
    }],
    // allow optionalDependencies
    'import/no-extraneous-dependencies': ['error', {
      'optionalDependencies': ['test/unit/index.js']
    }],
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
    //'vuefix/vuefix': [2, {'auto': true}]
  }
};

的package.json:

{
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --public localhost:8080 --open --inline --hot --host=0.0.0.0 --port=8080",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
    "eslint": "eslint --ext .js,.vue src"
  },
  "dependencies": {
    "@kazupon/vue-i18n-loader": "^0.2.1",
    "mdi": "^2.0.46",
    "nprogress": "^0.2.0",
    "vue": "^2.3.3",
    "vue-i18n": "^7.3.2",
    "vue-i18n-directives": "^3.0.1",
    "vue-i18n-extensions": "^0.1.0",
    "vue-i18n-loader": "^1.0.0",
    "vue-loader": "^13.0.5",
    "vue-resource": "^1.3.4",
    "vue-router": "^3.0.1",
    "vue-socket.io": "^2.1.1-a",
    "vue-template-compiler": "^2.3.3",
    "vuetify": "^0.16.9",
    "vuex": "^3.0.0",
    "normalizr": "^3.2.4",
    "vue-toasted": "^1.1.22",
    "yaml-loader": "^0.5.0"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "buble": "^0.16.0",
    "buble-loader": "^0.4.0",
    "cross-env": "^5.0.0",
    "css-loader": "^0.28.4",
    "eslint": "^4.9.0",
    "eslint-config-airbnb-base": "^12.0.0",
    "eslint-import-resolver-webpack": "^0.8.3",
    "eslint-plugin-html": "^3.2.2",
    "eslint-plugin-import": "^2.3.0",
    "eslint-plugin-vue": "^3.13.0",
    "eslint-plugin-vuefix": "^0.2.1",
    "file-loader": "^1.1.5",
    "style-loader": "^0.19.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.1",
    "vue-eslint-parser": "^1.0.0",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.4.5"
  }
}

我也遇到其他ES6功能无法正常工作的问题,比如对象扩展运算符,所以这可能是同一个问题?

1 个答案:

答案 0 :(得分:0)

如果没有看到你的package.json,我就会猜到它的ESLint。如果您使用Vue-CLI设置项目,则默认情况下会包含ESLint。如果您的代码没有以某种方式编写,则有一组规则会抛出错误。

检查你的.eslintrc.js,你可以添加规则。