How can I get the Amazon Cognito Identity SDK working in Aurelia?

岁酱吖の 提交于 2019-12-06 23:43:22

问题


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.

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

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"
}

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'

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'

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

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

Thanks, Nathan

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:

Error: ENOENT: no such file or directory, open '/Users/nathanskone/Projects/scc/aurelia-app/src/crypto.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'

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


回答1:


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"
}

UPDATE:

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"
    ],


来源:https://stackoverflow.com/questions/39714424/how-can-i-get-the-amazon-cognito-identity-sdk-working-in-aurelia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!