Vue: npm run dev报错Parsing error: The keyword 'import' is reserved
慕课网饿了么实战项目,把初始文件下载以后。
$ npm install
随后运行
$ npm run dev
以后报错:
npm run dev
> sell@1.0.0 dev /Users/macroot/myWorkspaces/sell
> node build/dev-server.js
Listening at http://localhost:8080
webpack built 7cdc45250a9732c5a0f9 in 983ms
Hash: 7cdc45250a9732c5a0f9
Version: webpack 1.15.0
Time: 983ms
Asset Size Chunks Chunk Names
app.js 285 kB 0 app
ERROR in ./src/main.js
✘ http://eslint.org/docs/rules/ Parsing error: The keyword 'import' is reserved
/Users/macroot/myWorkspaces/sell/src/main.js:1:1
import Vue from 'vue';
^
✘ 1 problem (1 error, 0 warnings)
Errors:
1 http://eslint.org/docs/rules/null
Child html-webpack-plugin for "index.html":
Asset Size Chunks Chunk Names
index.html 22 kB 0
webpack: Failed to compile.
^C
这是因为需要配置 eslint。
根据eslint说明[1],有两种配置。这里使用在项目目录下建立 .eslintrc.js
的方式来配置。
在项目目录下新建该文件
$ touch .eslintrc.js
把 .eslintrc.js
的内容更改为[2]:
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}
再次运行就正常了。
$ npm run dev
显示:
Listening at http://localhost:8080
参考