npm link "The file is marked as an executable but could not be run by the operating system."

npm link "The file is marked as an executable but could not be run by the operating system."

所以我用 package.json 创建了一个 cli,它指定了一个 bin 文件。

我已经npm link了。然后我在桌面上创建了一个新文件夹,npm link foocli 将它很好地安装到该目录的 node_modules 文件夹中。

然后我尝试从该目录 运行 cli 并抛出:

The file '/usr/local/bin/foocli' is marked as an executable but could not be run by the operating system.

知道是什么原因造成的吗?我该如何解决?

#!/usr/bin/env node 需要在正在执行的文件的顶部,以便 shell 知道如何执行文件。