【问题标题】:In Meteor: How to use a npm library that should be pulled from a repository?在 Meteor 中:如何使用应该从存储库中提取的 npm 库?
【发布时间】:2015-08-08 14:46:50
【问题描述】:

在我的 packages.json 文件中,我有:

{
    "sendwithus":"git+https://git@github.com/whalepath/sendwithus_nodejs.git#enable_testing_server"
}

因为我需要使用分叉(和固定版本的库)。上述语法适用于直节点。如何在流星中做到这一点?

这是我得到的错误:

=> Started proxy.                             
=> Errors prevented startup:                  
While reading package from `src/packages/npm-container`:
package.js:14:7: must declare exact version of dependency:
   sendwithus@git+https://git@github.com/whalepath/sendwithus_nodejs.git#enable_testing_server

更新:

我尝试删除该行并使用流星添加来获取包含的包:

失败:

meteor add sendwithus@2.9.1@https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4

=> Errors while parsing arguments:           

While adding package sendwithus@2.9.1@https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Package names can only contain lowercase ASCII alphanumerics, dash, dot, or colon, not "@".

失败:

$ meteor add sendwithus@2.9.1_https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
 => Errors while parsing arguments:           

While adding package sendwithus@2.9.1_https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Can't have two _ in version: 2.9.1_https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4

失败:

$ meteor add server:sendwithus@2.9.1@https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
 => Errors while parsing arguments:           

While adding package server:sendwithus@2.9.1@https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Package names can only contain lowercase ASCII alphanumerics, dash, dot, or colon, not "@".

失败:

$ meteor add sendwithus@https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
=> Errors while parsing arguments:           

While adding package sendwithus@https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Version string must look like semver (eg '1.2.3'), not 'https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4'.

【问题讨论】:

  • 你在用meteorhacks:npm包吗?
  • 是的,我是。那是负责错误消息的代码。 (但看起来负责的代码在 c 而不是 js 中)

标签: node.js meteor npm


【解决方案1】:

根据我发布到enter link description here时对这个问题的回答,唯一的解决方案是创建一个假的meteor包来包装新的节点库。

Npm.depends({sendwithus: "https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4"});

扩展这个答案: 只需使用 npm 库的分支就需要:

  1. 包/sendwithus/main.js:

    SendWithUs = Npm.require('sendwithus');

2。 包/sendwithus/package.js:

Package.describe({
   summary: 'Wrapped sendwithus library',
   version: '2.9.1',
   name: 'sendwithus'
}); 
Npm.depends({sendwithus: "https://github.com/whalepath/sendwithus_nodejs/tarball/41b0d177f6eabf02de2daec9bb2b36daebbfbef4"});

Package.onUse(function(api){
   api.addFiles('main.js', 'server');
   api.export('SendWithUs');
});
  1. 删除 packages.json 中的引用

  2. 流星添加sendwithus

  3. 使用 SendWithUs 变量

也许这可以改进?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2022-06-24
    • 2018-02-22
    • 2018-12-13
    相关资源
    最近更新 更多