问题
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