Nuxt application with amazon-cognito-identity-js package gives error fetch is not defined

最后都变了- 提交于 2020-04-12 07:06:08

问题


I included amazon-cognito-identity-js package in nuxt application and I want to use the sign in method/sign up methods which are provided by this package.

But I am getting following error

fetch is not defined

I installed node-fetch and modified node_module/amazon-cognito-identity-js/Clinet.js as below

const fetch = require('node-fetch');

that solves my prob but I dont want to modify node package.


回答1:


See the documentation:

Note: This library uses the Fetch API. For older browsers or in Node.js, you may need to include a polyfill. For example.

global.fetch = require('node-fetch');
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');



回答2:


I added following code.

import { CognitoUserPool, CognitoUserAttribute } from 'amazon-cognito-identity-js'

global.fetch = require('node-fetch')

That solved my problem.



来源:https://stackoverflow.com/questions/57540633/nuxt-application-with-amazon-cognito-identity-js-package-gives-error-fetch-is-no

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