今晚计划本地安装docsify,就用到了npm
打开cmd,输入:
npm -v
输出: 6.9.0
继续输入命令
npm install -g docsify-cli
报如下错误:
C:\Users\Lenovo>npm install -g docsify-cli
d:\nodejs\global\docsify -> d:\nodejs\global\node_modules\docsify-cli\bin\docsify
> docsify@4.12.2 postinstall d:\nodejs\global\node_modules\docsify-cli\node_modules\docsify
> opencollective-postinstall
Thank you for using docsify!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/docsify/donate
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\docsify-cli\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN node-fetch@2.6.7 requires a peer of encoding@^0.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.5.6 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.5.6 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
+ docsify-cli@4.4.3
added 213 packages from 93 contributors in 67.121s
C:\Users\Lenovo>docsify -v
'docsify' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
通过查询网上资料,尝试重新下载依赖组件,输入命令:
npm install
报如下错误:
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Lenovo\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Lenovo\package.json'
npm WARN Lenovo No description
npm WARN Lenovo No repository field.
npm WARN Lenovo No README data
npm WARN Lenovo No license field.
up to date in 0.47s
尝试更新npm,输入命令:
npm install -g npm
报如下错误:
d:\nodejs\global\npm -> d:\nodejs\global\node_modules\npm\bin\npm-cli.js
d:\nodejs\global\npx -> d:\nodejs\global\node_modules\npm\bin\npx-cli.js
+ npm@8.3.2
added 214 packages from 96 contributors in 18.755s
C:\Users\Lenovo>npm install -g docsify-cli
npm does not support Node.js v10.16.3
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
d:\nodejs\global\node_modules\npm\lib\npm.js:32
#unloaded = false
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at module.exports (d:\nodejs\global\node_modules\npm\lib\cli.js:22:15)
at Object.<anonymous> (d:\nodejs\global\node_modules\npm\bin\npm-cli.js:2:25)
at Module._compile (internal/modules/cjs/loader.js:778:30)
再次查看npm版本
npm -v
报如下错误
npm does not support Node.js v10.16.3
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
d:\nodejs\global\node_modules\npm\lib\npm.js:32
#unloaded = false
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at module.exports (d:\nodejs\global\node_modules\npm\lib\cli.js:22:15)
at Object.<anonymous> (d:\nodejs\global\node_modules\npm\bin\npm-cli.js:2:25)
at Module._compile (internal/modules/cjs/loader.js:778:30)
此时出现报错,npm版本和nodejs版本不符。
查看nodejs版本
node -v
显示为:v10.16.3
查看npm版本时会报上面的版本不符的错误。
输入下面网址查看npm和nodejs对应的版本信息
https://nodejs.org/zh-cn/download/releases/
查找对应的版本号,我的node版本10.16.3对应的npm版本号是6.9.0
然后在终端输入命令:
npm install -g npm@6.9.0
此时出现了npm用不了的情况
报错意思是:
您可能应该像我们一样升级到一个更新版本的节点
不能保证NPM将在这个版本中工作。
您可以在https://nodejs.org/上找到最新版本
nodejs的卸载重装
遇到问题:在控制面板招不到nodejs卸载,在nodejs文件夹也找不到unintall文件。
原来:nodejs有两个版本,一个是.msi版本,一个是.zip版本。前者提供了安装,修改。卸载的程序,后者只是一个压缩包,解压之后就能用,不需要安装。我之前的nodejs是zip版本。另外提一下,还有一个打包可执行文件工具pkg包,这个后面再研究。
安装nodejs的zip版本,下载完成后,放到指定目录,新建node_cache文件夹和node_global文件夹,如图:
环境变量修改
1.在系统变量栏新建配置如图:
2.在系统变量栏的path里面添加两个路径
%NODE_HOME%
%NODE_HOME%\node_global
为什么配置global路径,global会需要装一些工具命令包之类的
这两块环境变量配置完成后,保存关闭,重新打开cmd,如图测试:
配置
已经新建了node_cache文件夹和node_global文件夹,打开cmd,依次输入下面代码:
npm config set prefix "D:\software\nodejs\node_global"
npm config set cache "D:\software\nodejs\node_cache"
注意后面的“D:\software\nodejs\node_global”为自己软件安装路径的文件夹。
修改npm镜像为国内镜像,执行下面命令:
npm install -g cnpm --registry=https://registry.npm.taobao.org
如图:
通过下面代码可以查看配置
npm config list
备注:
将cnpm命令所在的⽬录添加到环境变量中,然后就可以使⽤cnpm。之后使⽤npm的地⽅都可以使⽤ cnpm。
npm init # 生成package.json文件,里面是各种依赖包的信息
npm install # 安装package.json文件的依赖包生成node_modules文夹
以上就是重装nodejs的全过程
然后输入
npm install -g docsify-cli
其中-g表示全局的意思
安装完成查看版本:
docsify -v
显示是4.4.3
本次安装完成。