使用cnpm总是不能成功安装插件包
来源:2-2 vue环境搭建以及vue-cli使用
Yoooshiki
2017-12-01
老师您好,我也是macOS系统,但是使用cnpm一直不能成功安装插件包,在之前的那个购物车课程中就是这样:
bogon:~ VitoYi$ cd /Users/mac/WebstormProjects/vue-demo1 bogon:vue-demo1 VitoYi$ cnpm i vue-cli -g Downloading vue-cli to /Users/mac/.node_modules_global/lib/node_modules/vue-cli_tmp [npminstall:get] retry GET http://registry.npm.taobao.org/vue-cli after 100ms, retry left 4, error: SyntaxError: Unexpected token < in JSON at position 0 [npminstall:get] retry GET http://registry.npm.taobao.org/vue-cli after 200ms, retry left 3, error: SyntaxError: Unexpected token < in JSON at position 0 [npminstall:get] retry GET http://registry.npm.taobao.org/vue-cli after 300ms, retry left 2, error: SyntaxError: Unexpected token < in JSON at position 0 [npminstall:get] retry GET http://registry.npm.taobao.org/vue-cli after 400ms, retry left 1, error: SyntaxError: Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at _get (/Users/mac/.node_modules_global/lib/node_modules/cnpm/node_modules/npminstall/lib/get.js:70:26) at _get.next (<anonymous>) at onFulfilled (/Users/mac/.node_modules_global/lib/node_modules/cnpm/node_modules/co/index.js:65:19) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) npminstall version: 3.2.1 npminstall args: /usr/local/bin/node /Users/mac/.node_modules_global/lib/node_modules/cnpm/node_modules/npminstall/bin/install.js --china --userconfig=/Users/mac/.cnpmrc --disturl=https://npm.taobao.org/mirrors/node --registry=http://registry.npm.taobao.org vue-cli -g bogon:vue-demo1 VitoYi$
只能通过npm成功安装。
但是安装成功之后还有一个问题,就是不会自动加入环境变量吗?
在之前的购物车的课程中就是,使用
$ npm install cnpm -g --registry=https://registry.npm.taobao.org $ npm install http-server -g
命令安装 cnpm 和 http-server 之后不起作用,还需要我手动添加环境变量才可以。
写回答
3回答
-
Yoooshiki
提问者
2017-12-02
问题已解决!
原因是,昨晚下载完node.js之后,跟着某个sb教程敲了些命令,改变了npm的prefix.
现已将全局路径设置为默认的
$ npm config set prefix /usr/local
问题解决。
032018-03-22 -
Yoooshiki
提问者
2017-12-01
跪求老师解答:我本事从事后端工作,前来补足前段缺陷,不曾想还没开始就结束了,一天时间了连个环境都没配起来,现在重装node.js, 连cpnm都挂了:
bogon:~ VitoYi$ npm install -g cnpm --registry=https://registry.npm.taobao.org /Users/mac/.node_modules_global/bin/cnpm -> /Users/mac/.node_modules_global/lib/node_modules/cnpm/bin/cnpm + cnpm@5.1.1 updated 1 package in 23.349s bogon:~ VitoYi$ bogon:~ VitoYi$ bogon:~ VitoYi$ bogon:~ VitoYi$ npm -v 5.5.1 bogon:~ VitoYi$ cnpm -v -bash: cnpm: command not found
00 -
Yoooshiki
提问者
2017-12-01
bogon:demo1 VitoYi$ npm install vue-cli -g /Users/mac/.node_modules_global/bin/vue -> /Users/mac/.node_modules_global/lib/node_modules/vue-cli/bin/vue /Users/mac/.node_modules_global/bin/vue-init -> /Users/mac/.node_modules_global/lib/node_modules/vue-cli/bin/vue-init /Users/mac/.node_modules_global/bin/vue-list -> /Users/mac/.node_modules_global/lib/node_modules/vue-cli/bin/vue-list + vue-cli@2.9.2 updated 1 package in 25.472s bogon:demo1 VitoYi$ vue init webpack-simple demo1 -bash: vue: command not found bogon:demo1 VitoYi$ vue -bash: vue: command not found
已经全局装了vue-cli ,但是还是command not found
00
相似问题