【问题标题】:creating own npx command - not running/does nothing创建自己的 npx 命令 - 不运行/什么都不做
【发布时间】:2020-11-28 16:24:50
【问题描述】:

我已经根据这篇文章创建了自己的 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: installed 290 in 25.638s。

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

关于可能导致此问题的任何想法?我原以为它会起作用。如果我将该包的 npm 安装到项目中,我可以进入目录并使用以下命令运行命令: node ./build/src/index.js 并且它运行没有问题。

【问题讨论】:

    标签: npm npx


    【解决方案1】:

    找到了我的问题的答案 - 我错过了入口文件中的 shebang 语句:

    #!/usr/bin/env 节点

    【讨论】:

    • 感谢您的跟进!这帮助我节省了数小时的糟糕谷歌搜索:)
    猜你喜欢
    • 2018-12-08
    • 2016-02-28
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2013-05-01
    • 1970-01-01
    • 2022-07-27
    相关资源
    最近更新 更多