Amplify.configure不是函数 [英] Amplify.configure is not a function

查看:148
本文介绍了Amplify.configure不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之后尝试将AWS Amplify与S3存储一起使用本教程以及手动设置.我创建了一个amplify-test.js文件,如下所示:

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));

但是当我运行node amplify-test.js时,出现以下错误:

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

Amplify.configure({ ^

Amplify.configure({ ^

TypeError:Amplify.configure不是一个函数 在对象. (C:\ Users \ Xiaoyun \ VuePwa \ aws-cognito-amplify-test \ src \ amplify-test.js:6:9) 在Module._compile(内部/模块/cjs/loader.js:702:30) 在Object.Module._extensions..js(内部/模块/cjs/loader.js:713:10) 在Module.load(internal/modules/cjs/loader.js:612:32) 在tryModuleLoad(内部/模块/cjs/loader.js:551:12) 在Function.Module._load(内部/模块/cjs/loader.js:543:3) 在Function.Module.runMain(内部/模块/cjs/loader.js:744:10) 在启动时(internal/bootstrap/node.js:238:19) 在bootstrapNodeJSCore(internal/bootstrap/node.js:572:3)

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)

我已经通过运行npm install aws-amplify --save安装了aws-amplify.我在做什么错了?

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

推荐答案

如果您使用的是const Amplify = require("aws-amplify");

使用

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.

这篇关于Amplify.configure不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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