【发布时间】: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 并且它运行没有问题。
【问题讨论】: