Powershell:设置 SASS_BINARY_PATH

Powershell: Setting SASS_BINARY_PATH

我需要使用我下载的本地文件设置 SASS_BINARY_PATH 环境变量,以便能够在企业防火墙后面安装 node-sass。所以在 windows cmd 上,我只是这样做:

SET SASS_BINARY_PATH=C:\Source\Repos\SRT\Srt.Web\sass-binary\v4.7.2\win32-x64-48_binding.node

并且安装工作正常,因为它成功设置了变量。但是当我尝试通过 Powershell 执行此操作时,它不起作用:

$env:SASS_BINARY_PATH="C:\Source\Repos\SRT\Srt.Web\sass-binary\v4.7.2\win32-x64-48_binding.node"

我还在 Powershell 上尝试了另一种方法:

[Environment]::SetEnvironmentVariable("SASS_BINARY_PATH", "C:\Source\Repos\SRT\Srt.Web\sass-binary\v4.7.2\win32-x64-48_binding.node", "Machine")

在控制面板上查看,成功添加了一个"SASS_BINARY_PATH"系统变量。但是在尝试重新安装 node-sass 时,它再次失败。

我的观察之一是,当我以 windows cmd 方式执行此操作,然后使用命令行 set 进行检查时,该变量与其他变量一起显示。但是当我同时使用这两种 Powershell 方法时,它并没有出现。对此有什么想法吗?

尝试通过企业防火墙 npm-install node-sass 时遇到的错误是:

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.7 .2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.7.2/win3 2-x64-48_binding.node":

HTTP error 401 Unauthorized

  • 手动下载 win32-x64-48_binding.node
  • 放在C:\Users\<user>\AppData\Roaming\npm-cache\node-sass.7.2文件夹中。
  • 然后尝试运行npm install node-sass

这里是@jengfad 基于上述解决方案使用的 PowerShell 命令,在讨论中有评论

$cacheSassPath = $env:APPDATA + '\npm-cache\node-sass' 

if( -Not (Test-Path -Path $cacheSassPath ) ) 
{ 

Write-Host "cacheSassPath not exists" 

New-Item -ItemType directory -Path $cacheSassPath 
Write-Host "cacheSassPath CREATED" 
} 

<# Ensure has no content #> 
Get-ChildItem -Path $cacheSassPath -Recurse| Foreach-object {Remove-item -Recurse -path $_.FullName } 

<# Copy local sass binary (~Srt.Web\sass-binary.7.2) file to cache folder #> 
$sassBinaryPath = split-path -parent $MyInvocation.MyCommand.Definition 
$sassBinaryPath = $sassBinaryPath + "\sass-binary.7.2" 

Copy-Item -Path $sassBinaryPath -Recurse -Destination $npmcachedir -Container 

Write-Host "node-sass binary file successfully copied!"