npm install 上缺少目录和文件

Missing directories and files on npm install

我正在尝试使用 npm i --save https://github.com/yagop/node-telegram-bot-api.git 安装 this module

我避免npm i --save node-telegram-bot-api的原因是我需要一些最近添加的方法(比如sendContact)。

当我安装时,它按预期添加到我的 package.json 中:

"node-telegram-bot-api": "git+https://github.com/yagop/node-telegram-bot-api.git",

但是当我尝试 运行 使用此模块的应用程序时,它说:

Error: Cannot find module './src/telegram'

仔细查看后发现缺少 src 和其他一些目录。这是 tree 输出:

$ tree ./node_modules/node-telegram-bot-api 
./node_modules/node-telegram-bot-api
├── CONTRIBUTING.md
├── index.js
├── LICENSE.md
├── node_modules
(second one is skipped)
├── package.json
├── README.hbs
└── README.md

为什么?我该如何解决?

我尝试 npm cache cleanrm -rf ./node_modules/node-telegram-bot-api,重新安装,没有任何帮助。

问题是存储库包含 .npmignore file 并且在安装过程中忽略了以下文件和目录:

# lcov
coverage/
*.log
.package.json

# artifacts & source
README.hbs
output.md
output/
src/
test/
examples/
lib-doc/

# dotfiles
.travis.yml
.eslintrc
.eslintignore
.editorconfig
.babelrc
.gitignore
.git

因此,如果您想使用存储库中的最新版本,您需要下载并手动安装。像那样:

cd ./node_modules
git clone https://github.com/yagop/node-telegram-bot-api
cd ./node_modules/node-telegram-bot-api
npm install

Upd.:(恕我直言)在这种情况下,为模块使用私有注册表是正确的。例如 sinopia.