如何从另一个Github项目中添加依赖?

7

使用命令创建新项目后:

npm init

我想从另一个GitHub项目添加依赖项,所以我使用了以下命令:

npm install https://github.com/cichy380/prefixData.git --save-dev

但是我遇到了错误:
npm ERR! code ENOPACKAGEJSON npm ERR! package.json 非注册包缺少 package.json: git+https://github.com/cichy380/prefixData.git。 npm ERR! package.json npm 在您的当前目录中找不到 package.json 文件。
你能解释一下为什么吗?

可能是如何从GitHub安装npm模块并构建它?的重复问题。 - Jordan Kasper
https://dev59.com/96Xja4cB1Zd3GeqPMB36的答案中提到了https://github.com/jameswomack/string-is-empty项目作为示例,但我没有添加此项目的问题(命令:'npm install https://github.com/jameswomack/string-is-empty --save-dev'正常运行)。 jameswomack / string-is-empty和cichy380 / prefixData项目有何不同? - Cichy
3个回答

6

我可以回答你的问题“你能为什么给我解释吗?”

考虑到问题中提供的有限信息,没有人能够确定地告诉你错误的根本原因,但可能是以下其中一个原因:

  1. The simplest problem could be there is no package.json in your repository; OR
  2. In your question you say that you executed the command:

    npm install https://github.com/cichy380/prefixData.git --save-dev
    

    This is not a valid npm package git url format. It's possible that if you used the protocol git+https you will not get that error, like so

    npm install git+https://github.com/cichy380/prefixData.git --save-dev
    

    I'm not sure if that's valid across all npm versions, but as you will see in the npm package docs link it does not allow for just https protocol; OR

  3. Two reasons I can't say for certain 2 is your problem is ONE, not sure what version npm package you're using and what npm versions obey the docs I provided as a link and TWO your error you provided includes the git+https protocol so thats confusing:

    npm ERR! package.json Non-registry package missing package.json: 
    git+https://github.com/cichy380/prefixData.git.
    
希望这对某些人有所帮助!

"http..." 是我的情况,而不是 "git+http..."。谢谢! - shameleo
"git+https" 对我有效。 - ThinkAndCode

0

我通过 validator 检查了 package.json 文件,发现了其中的错误。我进行了 fixed 并且现在 npm install ... 命令可以正常工作了!谢谢


这帮助我修复了 name - ATOzTOA

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接