Amplify.configure is not a function

不打扰是莪最后的温柔 提交于 2020-08-07 06:03:42

问题


Trying to use AWS Amplify with S3 Storage following this tutorial with the manual set up. I created an amplify-test.js file as follows:

// import Amplify from 'aws-amplify';
var Amplify = require('aws-amplify');

console.log(Amplify)

Amplify.configure({
    Auth: {
    // REQUIRED - Amazon Cognito Identity Pool ID
        identityPoolId: 'my identity pool id', 
    // REQUIRED - Amazon Cognito Region
        region: 'region', 
    // OPTIONAL - Amazon Cognito User Pool ID
        userPoolId: 'my user pool id',
    // OPTIONAL - Amazon Cognito Web Client ID
        userPoolWebClientId: 'XX-XXXX-X_abcd1234', 
    },
    Storage: {
        bucket: 's3 bucket', //REQUIRED -  Amazon S3 bucket
        region: 'XX-XXXX-X', //OPTIONAL -  Amazon service region
    }
});

Amplify.Storage.put('test.txt', 'Hello')
       .then (result => console.log(result))
       .catch(err => console.log(err));

But when I run node amplify-test.js, I got the following error:

Amplify.configure({ ^

TypeError: Amplify.configure is not a function at Object. (C:\Users\Xiaoyun\VuePwa\aws-cognito-amplify-test\src\amplify-test.js:6:9) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

I've already installed aws-amplify by running npm install aws-amplify --save. What am I doing wrong?


回答1:


If you are using const Amplify = require("aws-amplify");

With

Amplify.default.configure({ Auth: {

  // REQUIRED - Amazon Cognito Identity Pool ID
  identityPoolId: 'my identity pool id', 

  // REQUIRED - Amazon Cognito Region
  region: 'region', 

  // OPTIONAL - Amazon Cognito User Pool ID
  userPoolId: 'my user pool id',

  // OPTIONAL - Amazon Cognito Web Client ID
  userPoolWebClientId: 'XX-XXXX-X_abcd1234', 
},

Storage: {
  bucket: 's3 bucket', //REQUIRED -  Amazon S3 bucket
  region: 'XX-XXXX-X', //OPTIONAL -  Amazon service region
}

});

should solve your problem. It did for me.



来源:https://stackoverflow.com/questions/51372259/amplify-configure-is-not-a-function

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