NVM Bash的节点命令行工具:找不到

发布于 2025-01-21 08:55:12 字数 411 浏览 2 评论 0原文

我正在编写一个简单的节点CLI工具,并且使用NVM遇到麻烦。即使在本地安装了节点并使用NVM使用系统,并且仍然找不到CLI文件。代码仅包括外壳名称:

#!/usr/bin/env node

console.log("Hello, here is my first CLI tool")

从命令行运行此操作时,我会得到: -bash:cli-project:找不到命令

已经尝试了所有内容。节点为/usr/local/bin/node,甚至添加了。使用了节点的系统位置。已经添加了到 /etc /路径的路径。没有什么可用!有没有人使用NVM构建节点CLI工具的经验? NVM在我的计算机上正确设置,并且.bash_profile很好。非常困惑,为什么它不会走这条简单的途径。

I am writing a simple node CLI tool and having trouble using with NVM. Even installed node locally and use nvm use system and the CLI file still cannot be found. Code is simply including the shell designation:

#!/usr/bin/env node

console.log("Hello, here is my first CLI tool")

When running this from command line I get this:
-bash: cli-project: command not found

Have tried everything. Node is at /usr/local/bin/node, and have even added that. Have used system location of node. Have added the path to /etc/paths. Nothing works! Does anyone have experience building a node CLI tool using NVM how to set up initially? NVM is set up correctly on my machine, and .bash_profile is fine. Very puzzling why it won't pick up this simple path to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烏雲後面有陽光 2025-01-28 08:55:12

除了Shebang外,您还必须做一个小软件包。json魔术似乎是这样的:

"bin": {
    "cli-project": "index.js"
  },

然后在应用程序目录中进行npm链接。。作品!

You have to do a little package.json magic in addition to the shebang it seems like so:

"bin": {
    "cli-project": "index.js"
  },

Then do npm link . in the application directory. Works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文