我的Powershell脚本有问题。我想构建一个基于节点10.17.0的项目,然后将结果复制到另一基于节点8.11.4的项目中,然后运行该项目。
cd $PathToWebLibs
Write-Host "..........Switching to node v10.17.0.........." -ForegroundColor Magenta
nvm use 10.17.0
Write-Host "..........Building WebLibs.........." -ForegroundColor Magenta
npm run build_lib
Write-Host "..........Copying files from ($PathToWebLibs\dist\rsp\core-ui) to ($PathToSFP\node_modules\@rsp) .........." -ForegroundColor Magenta
cp -Recurse -Force ($PathToWebLibs + "\dist\rsp\core-ui") ($PathToSFP + "\node_modules\@rsp")
cd $PathToSFP
Write-Host "..........Switching to node v8.11.4.........." -ForegroundColor Magenta
nvm use 8.11.4
Write-Host "..........Starting SFP.........." -ForegroundColor Magenta
npm run start
问题在于,当nvm更改节点npm的版本时,无法识别。当我手动完成操作时,只需简单地一一键入命令即可。
nvm
设计为由shell在进程内运行,仅受POSIX兼容的shell(例如)支持bash
,而PowerShell不支持:
nvm
可在任何POSIX兼容外壳程序(sh,dash,ksh,zsh,bash)上运行,尤其是在以下平台上:unix,macOS和Windows WSL。
在类似Unix的平台上以及可能在WSL上,考虑使用Node.js版本管理器n
作为替代方案,它不依赖于修改当前Shell环境。
n
直接从GitHub安装;例如:curl -L https://git.io/n-install | bash
$PROFILE
文件中,或者通过Windows注册表中的持久性环境变量定义):$HOME/n/bin
必须添加到中$env:Path
,并且$env:PREFIX
必须设置为$HOME/n
(如果从WSL外部运行PowerShell,则相应地调整WSL的路径)。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句