创建自己的 npx 命令 - 不是 running/does 什么都没有
creating own npx command - not running/does nothing
我根据这篇文章创建了自己的 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 注册表中,我就会尝试 运行ning 命令,例如npx my-command,它什么都不做——除了显示:npx: installed 290 in 25.638s.
命令然后完成 运行ning,没有错误。
关于可能导致此问题的任何想法?我本以为它会起作用。如果我将该包 npm 安装到一个项目中,我可以进入目录并 运行 使用以下命令: node ./build/src/index.js 并且它 运行s 没有问题.
找到了我的问题的答案 - 我缺少条目文件中的 shebang 语句:
#!/usr/bin/env节点
我根据这篇文章创建了自己的 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 注册表中,我就会尝试 运行ning 命令,例如npx my-command,它什么都不做——除了显示:npx: installed 290 in 25.638s.
命令然后完成 运行ning,没有错误。
关于可能导致此问题的任何想法?我本以为它会起作用。如果我将该包 npm 安装到一个项目中,我可以进入目录并 运行 使用以下命令: node ./build/src/index.js 并且它 运行s 没有问题.
找到了我的问题的答案 - 我缺少条目文件中的 shebang 语句:
#!/usr/bin/env节点