前提條件
node安裝D盤:D:\nodejs,最開始安裝在D:\Program Files\nodejs,但是yarn的使用遇到了一些報(bào)錯(cuò)。
npm設(shè)置
在nodejs文件夾下創(chuàng)建
node_global和node_cache兩個(gè)文件夾。設(shè)置npm全局安裝位置:
npm config set prefix "D:\nodejs\node_global"設(shè)置npm緩存位置:
npm config set cache "D:\nodejs\node_cache"-
設(shè)置環(huán)境變量
用戶變量Path, 添加
D:\nodejs\node_global新建系統(tǒng)變量 NODE_PATH,
D:\nodejs\node_global\node_modules
yarn的安裝、設(shè)置和注意事項(xiàng)
安裝:
npm i -g yarn-
使用 yarn create 遇到的問題:
-
‘D:\Program‘ 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序;
原因:node 安裝目錄 D:\Program Files\nodejs ,中間有空格導(dǎo)致
解決辦法:重新安裝nodejs,安裝目錄不要帶空格
-
文件名、目錄名或卷標(biāo)語法不正確
原因:yarn包的安裝位置在C盤,D盤yarn沒有訪問權(quán)限導(dǎo)致
解決方法:重新設(shè)置全局安裝位置和緩存位置
-
查看yarn global、yarn cache目錄
yarn global dir
yarn cache dir在nodejs文件夾下創(chuàng)建yarn文件夾,在yarn下創(chuàng)建
global和cache文件夾。(在D盤找個(gè)位置存放就行)設(shè)置全局安裝位置和緩存位置到D盤
yarn config set global-folder "D:\nodejs\yarn\global"
yarn config cache-folder "D:\nodejs\yarn\cache"