如何在Aurelia中使用Amazon Cognito Identity SDK? [英] How can I get the Amazon Cognito Identity SDK working in Aurelia?

查看:79
本文介绍了如何在Aurelia中使用Amazon Cognito Identity SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Aurelia中使用Amazon Cognito Identity SDK。我没有太多的Javascript经验,并且对各种依赖系统都不熟悉。

I am trying to get the Amazon Cognito Identity SDK working in Aurelia. I do not have a lot of Javascript experience and am very unfamiliar with the various dependency systems.

我使用以下命令安装了Cognito SDK: npm install- -保存amazon-cognito-identity-js

I installed the Cognito SDK using: npm install --save amazon-cognito-identity-js

然后我编辑了 aurelia_project / aurelia.json 文件在build.bundles供应商-捆绑包依赖关系中包括新的客户端库依赖关系:

I then edited my aurelia_project/aurelia.json file as suggested in the Aurelia documentation to include a new client library dependency in build.bundles vendor-bundle dependencies:

"sjcl",
"jsbn",
{
  "name": "aws-sdk",
  "path": "../node_modules/aws-sdk/",
  "main": "dist/aws-sdk"
},
{
  "name": "amazon-cognito-identity-js",
  "path": "../node_modules/amazon-cognito-identity-js/dist",
  "main": "amazon-cognito-identity.min"
}

但是,当我尝试使用 au run 运行代码时,出现错误:错误:ENOENT:没有这样的文件或目录,打开'/Users/nathanskone/Projects/scc/aurelia-app/src/xmlbuilder.js'

However, when I try to run the code using au run I get the error: Error: ENOENT: no such file or directory, open '/Users/nathanskone/Projects/scc/aurelia-app/src/xmlbuilder.js'

我试图将xmlbuilder包含在我的aurelia.json中无济于事。当包含它时,我最终得到关于lodash的错误:错误:ENOENT:没有这样的文件或目录,打开'/ Users / nathanskone / Projects / scc / aurelia-app / src / lodash / object / Assign.js'

I have tried to include xmlbuilder in my aurelia.json to no avail. When it is included I end up getting this error about lodash: Error: ENOENT: no such file or directory, open '/Users/nathanskone/Projects/scc/aurelia-app/src/lodash/object/assign.js'

我还没有找到克服lodash错误的方法。

I haven't found any way to get past the lodash error.

是否有人熟悉Aurelia依赖系统可以提供帮助?

Is there anyone out there familiar with the Aurelia dependency system that could help?

谢谢,
内森(Nathan)

Thanks, Nathan

编辑#2::尽管我克服了xmlbuilder / lodash错误,但在尝试捆绑aws-sdk时遇到了更多错误。这是我当前的aurelia.json:

EDIT #2: While I got past the xmlbuilder/lodash errors, I have run into further errors trying to bundle the aws-sdk. Here is my current aurelia.json:

"dependencies": [
  {
    "name": "xmlbuilder",
    "path": "../node_modules/xmlbuilder/lib",
    "main": "index"
  },
  {
    "name": "aws-sdk",
    "path": "../node_modules/aws-sdk",
    "main": "index",
    "resources": ["lib/region_config.json"]
  },

我目前得到的错误是:

And the error I am currently getting:

错误:ENOENT:没有这样的文件或目录,打开'/ Users / nathanskone / Projects / scc / aurelia-app / src / crypto。 js'

如果我删除资源(lib / region_config.json),则会出现此错误:
错误:ENOENT:没有这样的文件或目录,打开'/Users/nathanskone/Projects/scc/aurelia-app/node_modules/aws-sdk/lib/region_config.json.js'

If I remove the resources (lib/region_config.json) then I get this error instead: Error: ENOENT: no such file or directory, open '/Users/nathanskone/Projects/scc/aurelia-app/node_modules/aws-sdk/lib/region_config.json.js'

我认为加密实际上是aws-sdk / lib / util.js中定义的对象,而aws-sdk / lib / region_config.js必需。

I think crypto is actually an object defined in aws-sdk/lib/util.js, which is required by aws-sdk/lib/region_config.js.

解决方案

请改用已编译的库,使用捆绑好的已编译的lib即可。
此外,该库似乎还定义了 window.AWS ,因此无论是否注入,都可以使用

Try the compiled library instead, using the compiled lib bundled just fine. Also the library seems to define window.AWS, so injecting it or not will work

{
    "name": "aws-sdk",
    "path": "../node_modules/aws-sdk/dist",
    "main": "aws-sdk.min",
    "exports": "AWS"
}

更新:

似乎导入这些库的唯一方法是使用prepend部分,这些库将内容写入window变量,这样,即使不像ES6模块那样将其导入,它仍可用于您的应用程序脚本。

It seems the only way to import those libraries is by using the prepend section, the libraries write to the window variable so it can still be accesible to your app scripts, only by not importing them like ES6 modules.

    "prepend": [
      "node_modules/aws-sdk/dist/aws-sdk.min.js",
      "node_modules/amazon-cognito-identity-js/dist/aws-cognito-sdk.min.js",
      "node_modules/amazon-cognito-identity-js/dist/amazon-cognito-identity.min.js",
      "node_modules/bluebird/js/browser/bluebird.core.js",
      "scripts/require.js"
    ],

这篇关于如何在Aurelia中使用Amazon Cognito Identity SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆