简体   繁体   English

我自己的 NPM package 不工作 找不到命令

[英]my own NPM package not working command not found

If I don't install my own CLI globally, I can't run it with my keyword command.如果我不在全局安装我自己的 CLI,我将无法使用我的关键字命令运行它。 Only if I install the NPM package globally, the start works with my keyword.仅当我在全局安装 NPM package 时,开始使用我的关键字。 I would like to install it with the command suggested by NPM and then run it with keyword.我想用 NPM 建议的命令安装它,然后用关键字运行它。

Visit my CLI: https://www.npmjs.com/package/sweetstack访问我的 CLI: https://www.npmjs.com/package/sweetstack

Installation as globally it works, started with sweetstack.安装在全球范围内有效,从 sweetstack 开始。

npm i -g sweetstack

Installation as local not working.安装为本地不起作用。

npm i sweetstack

This behavior is expected, if your inspect the $PATH environment variables of your shell, you'll see that only the directory containing the globally installed packages is present.此行为是预期的,如果您检查 shell 的$PATH环境变量,您将看到只有包含全局安装包的目录存在。

If you want to install your tool locally (which is a good practice), you then have to run it through npx .如果你想在本地安装你的工具(这是一个很好的做法),你必须通过npx运行它。

The associated documentation page details what it does more clearly and it's relation to npm exec : https://docs.npmjs.com/cli/v9/commands/npx相关文档页面更清楚地详细说明了它的作用以及它与npm exec的关系: https://docs.npmjs.com/cli/v9/commands/npx

cd ./your-project
npm i sweetstack

npx sweetstack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM