Uncaught SyntaxError: Unexpected identifier 报错 import Vue from 'vue';

一般情况是因为Webpack与webpack-dev-server版本不兼容导致。

{
  "name": "vue-loader-demo",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "dev": "webpack-dev-server --inline --hot  --port 8082"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.4.4",
    "build": "^0.1.4",
    "vue": "^1.0.28"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.5",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "css-loader": "^2.1.1",
    "vue-hot-reload-api": "^1.3.2",
    "vue-html-loader": "^1.2.4",
    "vue-loader": "^8.5.4",
    "vue-style-loader": "^4.1.2",
    "webpack": "^1.13.1",
    "webpack-cli": "^3.3.2",
    "webpack-dev-server": "^1.15.0"
  }
}

一般情况是因为Webpack与webpack-dev-server版本不兼容导致。
像我也出现此问题,我电脑的webpack是1.13.1,但webpack-dev-server是2.x以上的版本。
当我将webpack-dev-server卸载掉:npm uninstall webpack-dev-server -g
然后安装1.15.0版本的webpack-dev-server,就可解决了此问题。:npm install webpack-dev-server@1.15.0 -g

上一篇:error: Unexpected console statement (no-console)


下一篇:Linux 提示“syntax error: unexpected end of file”