【问题标题】:Powershell: Setting SASS_BINARY_PATHPowershell:设置 SASS_BINARY_PATH
【发布时间】:2017-11-26 11:17:51
【问题描述】:

我需要使用我下载的本地文件设置 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 时遇到的错误是:

从以下位置下载二进制文件 https://github.com/sass/node-sass/releases/download/v4.7 .2/win32-x64-48_binding.node 无法下载 "https://github.com/sass/node-sass/releases/download/v4.7.2/win3 2-x64-48_binding.node”:

HTTP 错误 401 未经授权

【问题讨论】:

  • 你试过this windows 指令吗?你需要先安装 Ruby,然后再安装 SASS gem 包
  • 我没有尝试安装 ruby​​ 和 via gem,因为我希望它安装在 npm 上,以便它可以在 Jenkins 上自动触发。
  • 那你试过npm install node-sass吗?如果是,发生了什么?
  • 正如我上面解释的那样,它失败了,因为当我尝试使用 powershell 方法时它找不到 sass_binary_path。
  • 我猜这还不够,你能把尝试执行时的完整错误信息npm install node-sass

标签: powershell node-sass


【解决方案1】:
  • 手动下载win32-x64-48_binding.node
  • 放入C:\Users\<user>\AppData\Roaming\npm-cache\node-sass\4.7.2文件夹。
  • 然后尝试运行npm install node-sass

这是基于上述解决方案使用的 PowerShell 命令@jengfad,讨论中对此进行了评论

$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\4.7.2) file to cache folder #> 
$sassBinaryPath = split-path -parent $MyInvocation.MyCommand.Definition 
$sassBinaryPath = $sassBinaryPath + "\sass-binary\4.7.2" 

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

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

【讨论】:

    猜你喜欢
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多