You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于npx与pnpm搭配使用及本地二进制文件执行的技术咨询

关于npx与pnpm搭配使用及本地二进制文件执行的技术咨询

Hey there! Let's clear up your confusion around npx and pnpm:

First off, using npx directly with packages installed via pnpm usually doesn't work smoothly. That's because npx is tied to npm's ecosystem by default—it checks npm's cache or remote repositories first, and doesn't automatically recognize the local binary paths that pnpm uses.

You're totally right about pnpx behaving more like npm create by default—it prioritizes fetching remote packages to execute instead of using locally installed ones. But pnpm does have dedicated tools to run local binaries, and a few workarounds if you need specific behavior:

  • Use pnpm exec (the official pnpm equivalent)
    This is the go-to command for running locally installed binaries with pnpm. For example, if you have eslint installed in your project, just run pnpm exec eslint .—it'll directly use the local version without reaching for remote resources. It's designed specifically for this use case, so it's way more reliable than trying to force npx to work with pnpm.

  • Leverage pnpx with a flag
    If you still want to use pnpx, you can add the --no-install flag: pnpx --no-install <package-name>. This tells pnpx to only look for locally installed packages instead of downloading remote ones. It works, but pnpm exec is more intuitive for this scenario.

  • Manual path workaround for npx (not recommended)
    If you really need to use npx with pnpm's local binaries, you can manually point to the binary in your node_modules/.bin directory, like npx ./node_modules/.bin/eslint. This works, but it's clunky and not ideal for regular use.

If you're working with scripts defined in your package.json, you can also just use pnpm run <script-name>—pnpm will automatically use the local binaries referenced in those scripts.

备注:内容来源于stack exchange,提问作者Matt Sanders

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 13:52:37