创建自己的npx命令-不运行/不执行任何操作

时间:2020-08-08 15:08:57

标签: npm npx

在本文的指导下,我创建了自己的npx命令:https://www.danielbischoff.com/blog/2018-09-23--cli-scripts-with-npm/

我拥有的项目是打字稿,我正在使用tsc进行转换。我的tsconfig看起来像这样:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "declaration": true,
        "declarationDir": "build",
        "target": "es5",
        "module": "umd" ,
        "strict": true,
        "esModuleInterop",
        "outDir": "build",
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true
    },
    "types": ["node"],
    "typeRoots": ["../node_modules/@types"],
    "include": ["src/**/*"],
    "exclude": ["node_modules", "build"]
}

在package.json中,我具有bin和main的属性,如下所示:

  "main": "./build/index.js",
  "bin": "./build/index.js",

在本地测试时,如果我运行“ npx”。在与package.json相同的级别上,我创建的命令将按预期运行。

但是,一旦它发布到我的私人npm注册表中,我尝试运行该命令,例如npx my-command,它什么也没做-除了显示:npx:在25.638秒内安装了290。

该命令随后完成运行,没有错误。

关于可能是什么原因的任何想法?我希望它能工作。如果我将该软件包进行npm安装到项目中,则可以进入目录并使用以下命令运行该命令:node ./build/src/index.js,它可以正常运行。

1 个答案:

答案 0 :(得分:0)

找到了解决我问题的方法-我从入口文件中丢失了shebang语句:

#!/ usr / bin / env节点