npm 없으면 설치

This commit is contained in:
Jerry Chae committed 2026-05-13 20:03:18 +09:00
1 parent 51cfb95b81
commit eb52bbd9d3
2 files changed
+76 -1

No files matched your search

+31 -1
View File
@@ -79,7 +79,37 @@ function ErrExit { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 }
Info "Platform: $([System.Environment]::OSVersion.Platform) ($([System.Environment]::GetEnvironmentVariable('PROCESSOR_ARCHITECTURE')))"
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
ErrExit "npm is required. Install Node.js 18+: https://nodejs.org/"
Info "npm is not installed. Installing Node.js (includes npm) via winget..."
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
ErrExit "Neither npm nor winget is available. Install Node.js 18+ manually: https://nodejs.org/"
}
winget install --id OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements 2>&1 | Out-Null
# Refresh PATH and verify npm is now available
$env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
# Search common Node.js install paths
$nodePaths = @(
(Join-Path $env:ProgramFiles 'nodejs'),
(Join-Path $env:ProgramFiles(x86) 'nodejs'),
(Join-Path $env:LOCALAPPDATA 'Programs\nodejs')
)
foreach ($np in $nodePaths) {
if ((Test-Path $np) -and ($env:Path -notlike "*$np*")) {
$env:Path = "$np;$env:Path"
break
}
}
}
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
ErrExit "Node.js installation completed but npm not found. Please restart your terminal and run this script again."
}
Success "Node.js installed via winget"
}
# ────────────────────────────────────────────