从远程仓库中获取并获取:"解析错误:关键字“导入”#39;保留"

时间:2016-03-11 04:16:54

标签: javascript ecmascript-6 package.json

我收到以下错误:

ERROR in ./src/main.js

  error Parsing error: The keyword 'import' is reserved  
  /Users/staging/Desktop/sourcetree/viewer_web/src/main.js:1:1
  import Vue from 'vue'

由于某些原因,我的项目中的ES6功能无法识别?

我使用的是Node 5.0,这是我的package.json

{
  "name": "istaging-viewer",
  "description": "A Vue.js project",
  "author": "Alex <alexchen.info@gmail.com>",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "build": "rimraf dist && webpack --progress --hide-modules --config build/webpack.prod.conf.js",
    "test": "karma start build/karma.conf.js --single-run"
  },
  "dependencies": {
    "aframe": "mozvr/aframe#dev",
    "bootstrap": "^3.3.6",
    "jquery": "^2.2.1",
    "lodash": "^4.4.0",
    "vue": "^1.0.16",
    "vue-resource": "^0.7.0",
    "vue-router": "^0.7.11"
  },
  "devDependencies": {
    "babel-core": "^6.0.0",
    "babel-loader": "^6.0.0",
    "babel-plugin-transform-runtime": "^6.0.0",
    "babel-preset-es2015": "^6.0.0",
    "babel-preset-stage-2": "^6.0.0",
    "babel-runtime": "^5.8.0",
    "bootstrap-webpack": "0.0.5",
    "connect-history-api-fallback": "^1.1.0",
    "css-loader": "^0.23.1",
    "eslint": "^1.10.3",
    "eslint-friendly-formatter": "^1.2.2",
    "eslint-loader": "^1.2.0",
    "eslint-plugin-html": "^1.3.0",
    "eventsource-polyfill": "^0.9.6",
    "exports-loader": "^0.6.3",
    "express": "^4.13.3",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.4",
    "function-bind": "^1.0.2",
    "html-loader": "^0.4.3",
    "html-webpack-plugin": "^2.8.1",
    "imports-loader": "^0.6.5",
    "inject-loader": "^2.0.1",
    "jasmine-core": "^2.4.1",
    "json-loader": "^0.5.4",
    "karma": "^0.13.15",
    "karma-jasmine": "^0.3.6",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-spec-reporter": "0.0.24",
    "karma-webpack": "^1.7.0",
    "less": "^2.6.0",
    "less-loader": "^2.2.2",
    "phantomjs-prebuilt": "^2.1.3",
    "rimraf": "^2.5.0",
    "style-loader": "^0.13.0",
    "stylus": "^0.53.0",
    "stylus-loader": "^1.5.1",
    "url-loader": "^0.5.7",
    "vue-hot-reload-api": "^1.2.0",
    "vue-html-loader": "^1.0.0",
    "vue-loader": "^8.1.3",
    "vue-style-loader": "^1.0.0",
    "webpack": "^1.12.2",
    "webpack-dev-middleware": "^1.4.0",
    "webpack-hot-middleware": "^2.6.0"
  }
}

可能的解决方案是什么?

我认为这是eslint造成的问题,所以我在全球范围内安装了它,但它没有解决问题。

2 个答案:

答案 0 :(得分:4)

您应该将其添加到.eslintrc文件中:

"parser": "babel-eslint"

这将解决您的问题。

答案 1 :(得分:1)

节点仍然使用common.js作为模块。在这里查看https://nodejs.org/en/docs/es6/以获取节点中所有es6支持的功能。如果你想使用es6导入,你可能必须使用babel-node