node.js - 术语 'gulp' 未被识别为 cmdlet 错误的名称

标签 node.js windows powershell gulp

因此,我尝试在我们的构建服务器上运行 gulp,但不断出现上述错误。如果我使用我的用户帐户登录构建服务器,一切正常,因为我在我的帐户下全局安装了 gulp,但是当 Jenkins 运行我的 powershell 脚本时,它失败并出现错误:

The term 'gulp' is not recognized as the name of a cmdlet error

所以我尝试在我的脚本中进行全局安装,以便它与 Jenkins 使用的任何用户一起安装。

然后我在powershell脚本中添加了npm -g ls,发现它是在系统用户下全局安装的:

C:\Windows\system32\config\systemprofile\AppData\Roaming\npm > gulp@3.9.0

由于我仍然收到错误,所以我接受了 this post 的建议并在上面的目录中添加了一个路径变量,但仍然出现相同的错误。

有人知道我接下来可以尝试什么吗?我很困惑为什么它不起作用。

最佳答案

确保包含 gulp.exe 的目录包含在 $env:PATH 环境变量中。您可以使用 [Environment]::SetEnvironmentVariable() 方法更新机器范围的 PATH 变量。

让我们假设 gulp 可执行文件的路径是 C:\Program Files\gulp\bin\gulp.exe

# Directory containing exe
$GulpFolderPath = 'C:\program files\gulp\bin'

# Retrieve user-agnostic PATH environment variable value
$CurrentEnvPath = [Environment]::GetEnvironmentVariable('PATH','Machine')

# Check if PATH already contains gulp
if($CurrentEnvPath -split ';' -notcontains $GulpFolderPath)
{
    # if not, update it
    $NewEnvPath = $CurrentEnvPath,$GulpFolderPath -join ';'
    [Environment]::SetEnvironmentVariable('PATH',$NewEnvPath,'Machine')
}

关于node.js - 术语 'gulp' 未被识别为 cmdlet 错误的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35159401/

相关文章:

api - jade 模板中有 substr 方法吗?

powershell - 将输入变量从批处理文件发送到 powershell 脚本

node.js - 如何使用 Mailchimp 的 API v3 执行 "delete and remove"(不是 "delete and archive")?

node.js - 如何在 Node redis中设置hmset的过期时间?

node.js - Haste 模块映射中不存在模块 `fs`

c# - 无法使用变量名保存位图图像

Windows 上的 Python WSGI 部署用于 CPU 密集型应用程序

mysql - Perl DBI 模块中的操作失败未指示错误

Powershell 变量包含该值两次

powershell - Where-Object 和数组未正确过滤