问题描述:
今天我学vue的插件Nuxt.js的时候,根据官网下载Nuxt的模板,然后cd到项目中,npm run dev
的时候报下班的错误
npm run dev
> my-project@1.0.0 dev /Users/zhangxi/Documents/study/demo/vue/nuxtjs/my-project
> nuxt
/Users/zhangxi/Documents/study/demo/vue/nuxtjs/my-project/node_modules/nuxt/lib/core/middleware/nuxt.js:72
const policies = this.options.render.csp.policies ? {...this.options.render.csp.policies} : null
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/zhangxi/Documents/study/demo/vue/nuxtjs/my-project/node_modules/nuxt/lib/core/renderer.js:19:24)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-project@1.0.0 dev: `nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-project@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/zhangxi/.npm/_logs/2018-07-05T08_57_08_585Z-debug.log
通过科学上网,从github中查询到了这个问题,主要是因为你的node版本过低,需要升级node版本即可
1. Mac升级node
第一步,先查看本机node.js版本:
$ node -v
第二步,清除node.js的cache:
$ sudo npm cache clean -f
第三步,安装 n 工具,这个工具是专门用来管理node.js版本的,别怀疑这个工具的名字,是他是他就是他,他的名字就是 "n"
$ sudo npm install -g n
第四步,安装最新版本的node.js
$ sudo n stable
第五步,再次查看本机的node.js版本:
$ node -v
感谢简书ChenME提供的《关于Mac升级Node的快捷方法》
zhangxi@zhangxideMacBook-Air:~/Documents/study/demo/vue/nuxtjs/my-project|
⇒ node -v
v8.1.2
zhangxi@zhangxideMacBook-Air:~/Documents/study/demo/vue/nuxtjs/my-project|
⇒ sudo npm cache clean -f
Password:
npm WARN using --force I sure hope you know what you are doing.
zhangxi@zhangxideMacBook-Air:~/Documents/study/demo/vue/nuxtjs/my-project|
⇒ sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@2.1.12
added 1 package from 4 contributors in 6.483s
zhangxi@zhangxideMacBook-Air:~/Documents/study/demo/vue/nuxtjs/my-project|
⇒ sudo n stable
install : node-v10.6.0
mkdir : /usr/local/n/versions/node/10.6.0
fetch : https://nodejs.org/dist/v10.6.0/node-v10.6.0-darwin-x64.tar.gz
######################################################################## 100.0%
installed : v10.6.0
zhangxi@zhangxideMacBook-Air:~/Documents/study/demo/vue/nuxtjs/my-project|
⇒ node -v
v10.6.0
2. 根据官网下载模板
vue init nuxt-community/starter-template my-project
cd my-project
npm i
npm run dev
image.png
网友评论