Install any skill in seconds. Free to start, no credit card required.
Get Started Free →取得 node_modules 中已安裝的 Node.js 模組路徑。當需要 (1) 查找已安裝模組的位置,(2) 取得 package.json 路徑,(3) 解析模組入口點,(4) 在 pnpm Yarn 環境下搜尋套件時使用此技能。此技能支援 PowerShell、cmd、Node.js 和 bash 等多種方法來搜尋 node_modules 中的套件路徑。/ Get installed Node.js module paths in node_modules. Use when (1) Finding installed module locations, (2) Getting package.json path, (3) Resolving module entry point, (4) Searching packages in pnpm Yarn environments. Supports PowerShell, cmd, Node.js and bash methods.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 76% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 118% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 451% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 87% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 175% | 0% |
取得 node_modules 中已安裝模組的路徑 / Get installed module paths in node_modules
本技能提供多種方法來取得 Node.js 專案中已安裝模組的路徑,適用於不同環境(npm、pnpm、Yarn)和不同工具需求。
pnpm 使用獨特的目錄結構:
.pnpm/ 目錄下node_modules/ 中的套件是符號連結(symbolic link)node_modules/
├── env-bool → .pnpm/env-bool@2.0.2/node_modules/env-bool
└── .pnpm/
└── env-bool@2.0.2/
└── node_modules/
└── env-bool/當 OpenCode Glob 工具無法找到 pnpm 的符號連結時:
require.resolve().pnpm/ 目錄執行環境:PowerShell
powershellpowershell -Command '$p="node_modules"; $f="<pkg>"; Get-ChildItem -Path $p -Filter $f -ErrorAction SilentlyContinue | ForEach-Object { Write-Output ("`n" + $_.FullName); Get-ChildItem -Path $_.FullName -ErrorAction SilentlyContinue | ForEach-Object { $s = ""; if($_.PSIsContainer){$s="/"}; "├─ " + $_.Name + $s } }'
範例(查詢 env-bool):
powershellpowershell -Command '$p="node_modules"; $f="env-bool"; Get-ChildItem -Path $p -Filter $f -ErrorAction SilentlyContinue | ForEach-Object { Write-Output ("`n" + $_.FullName); Get-ChildItem -Path $_.FullName -ErrorAction SilentlyContinue | ForEach-Object { $s = ""; if($_.PSIsContainer){$s="/"}; "├─ " + $_.Name + $s } }'
輸出:
D:\project\node_modules\env-bool
├─ dist/
├─ package.json
├─ src/powershellpowershell -Command '$p="node_modules"; $f="*<關鍵字>*"; Get-ChildItem -Path $p -Filter $f -ErrorAction SilentlyContinue | ForEach-Object { Write-Output ("`n" + $_.FullName); Get-ChildItem -Path $_.FullName -ErrorAction SilentlyContinue | ForEach-Object { $s = ""; if($_.PSIsContainer){$s="/"}; "├─ " + $_.Name + $s } }'
範例(搜尋包含 env 的套件):
powershellpowershell -Command '$p="node_modules"; $f="*env*"; Get-ChildItem -Path $p -Filter $f -ErrorAction SilentlyContinue | ForEach-Object { Write-Output ("`n" + $_.FullName); Get-ChildItem -Path $_.FullName -ErrorAction SilentlyContinue | ForEach-Object { $s = ""; if($_.PSIsContainer){$s="/"}; "├─ " + $_.Name + $s } }'
執行環境:cmd.exe
cmdcmd /c "echo %cd%\node_modules\<pkg> & for /f "delims=" %i in ('dir node_modules\<pkg> /b') do @for %j in ("node_modules\<pkg>\%i") do @echo ├─ [%~aj] %i"
範例:
cmdcmd /c "echo %cd%\node_modules\env-bool & for /f "delims=" %i in ('dir node_modules\env-bool /b') do @for %j in ("node_modules\env-bool\%i") do @echo ├─ [%~aj] %i"
輸出:
D:\Users\WebstormProjects\nodejs-yarn\jest-plugin-fixme-suite\node_modules\env-bool
├─ [--a--------] CHANGELOG.md
├─ [d----------] dist
├─ [--a--------] package.json
├─ [--a--------] README.md
├─ [d----------] srccmdcmd /c "dir node_modules\<pkg>"
範例:
cmdcmd /c "dir node_modules\env-bool"
輸出:
D:\Users\WebstormProjects\nodejs-yarn\jest-plugin-fixme-suite\node_modules\env-bool 的目錄
2026/04/09 下午 01:49 <DIR> .
2026/04/09 下午 01:49 <DIR> ..
2026/04/09 下午 01:49 1,406 CHANGELOG.md
2026/04/09 下午 01:49 3,804 package.json
2026/04/09 下午 01:49 4,580 README.md
2026/04/09 下午 01:49 1 <DIR> dist
2026/04/09 下午 01:49 1 <DIR> src
3 個檔案 9,790 位元組
4 個目錄 1,539,959,083,008 位元組可用cmdcmd /c "dir node_modules\<pkg> /s /b"
執行環境:Node.js
bashnode -e "console.log(require.resolve('<pkg>'))"
範例:
bashnode -e "console.log(require.resolve('env-bool'))"
輸出:
D:\project\node_modules\.pnpm\env-bool@2.0.2\node_modules\env-bool\dist\index.cjsbashnode -e "console.log(require.resolve('<pkg>/package.json'))"
執行環境:bash(WSL、Git Bash)
bashbash -c "find node_modules -name '<pkg>' -type d"
範例:
bashbash -c "find node_modules -name 'env-bool' -type d"
輸出:
node_modules/env-boolbashbash -c "ls -d node_modules/*/<pkg>"
範例:
bashbash -c "ls -d node_modules/*/env-bool"
| 需求 | 方法 | 命令 | |------|------|------| | 搜尋套件目錄 | PowerShell | powershell -Command '$p="node_modules"; $f="<pkg>"; Get-ChildItem -Path $p -Filter $f' | | 模糊搜尋 | PowerShell | powershell -Command '$p="node_modules"; $f="*env*"; Get-ChildItem -Path $p -Filter $f' | | 搜尋套件並顯示檔案 | cmd | cmd /c "dir node_modules\<pkg>" | | 遞迴搜尋 | cmd | cmd /c "dir node_modules\<pkg> /s /b" | | 取得入口點 | Node.js | node -e "console.log(require.resolve('<pkg>'))" | | 取得 package.json | Node.js | node -e "console.log(require.resolve('<pkg>/package.json'))" | | 搜尋目錄 | bash | bash -c "find node_modules -name '<pkg>' -type d" |
需要搜尋 node_modules 中的套件?
│
├─ 是 → 使用 PowerShell?(推薦)
│ │
│ ├─ 是 → powershell 指令
│ │
│ └─ 否 → 使用 cmd?
│ │
│ ├─ 是 → cmd 指令
│ │
│ └─ 否 → 使用 bash?
│ │
│ ├─ 是 → bash 指令
│ │
│ └─ 否 → node 指令
│
└─ 否 �� 結束原因:OpenCode Glob 工具無法處理 pnpm 的符號連結結構
解決方案:
require.resolve().pnpm/ 目錄原因:套件未正確安裝或路徑錯誤
解決方案:
bash# 檢查是否已安裝 pnpm list <套件名稱> # 重新安裝 pnpm add <套件名稱>
完整的搜尋方法與流程請參考:
Other measured skills in the registry, with their headline benchmark lift.