【问题标题】:npm package.json defined bin module - command not foundnpm package.json 定义的 bin 模块 - 找不到命令
【发布时间】:2017-10-19 00:07:17
【问题描述】:

我在 package.json 中定义的 bin 模块上收到 command not found...为什么?我认为它应该自动将本地命令映射到路径中。

在我模块的 package.json 中:

  "bin": {
    "testme": "./misc/testme"
  },

./misc/testme 脚本:

#!/usr/bin/env node
console.log("this is a test");

出现在node_modules/.bin目录中

$ ls node_modules/.bin
acorn       escodegen    gulp        kue-dashboard  ncp                 semver               stylus
cake        esgenerate   gzip-size   lessc          nopt                shjs                 testme
cleancss    esparse      handlebars  make-plural    pretty-bytes        sshpk-conv           uglifyjs
coffee      esvalidate   image-size  messageformat  rc                  sshpk-sign           user-home
dateformat  express      jade        mime           retrieve-arguments  sshpk-verify         uuid
dot-object  geojsonhint  jsonlint    mkdirp         rimraf              strip-indent         watchr
errno       grunt        js-yaml     mustache       sails               strip-json-comments  which

但是,当我运行 npm install 之后,我得到:

$ testme
bash: testme: command not found...

【问题讨论】:

    标签: node.js npm npm-install package.json


    【解决方案1】:

    对我来说,在 Windows 上必须运行

    npm 链接

    在命令开始执行之前在我的项目的根文件夹中。我不知道它是否适用于其他操作系统

    【讨论】:

      【解决方案2】:

      我相信只有在全局安装软件包时才能运行testme。要运行此命令(无需全局安装),您必须 npm run testme 并将其添加到您的 package.json 文件中:

      "scripts": {
          "testme": "./bin/testme"
      

      更多信息在这里:http://2ality.com/2016/01/locally-installed-npm-executables.html

      【讨论】:

        【解决方案3】:

        有 2 种方法(我可以想到运行此命令):-

        a(如@TAMAS 所说)。

         npm install -g testme 
        

        b.

         PATH = $PATH/your/project/dir/node_modules/.bin
        
         EXPORT PATH
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-08-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-08
          • 2020-06-26
          相关资源
          最近更新 更多