Smit
Smit

Reputation: 39

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

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.

Upvotes: 0

Views: 516

Answers (2)

Smit
Smit

Reputation: 39

I added following code.

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

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

That solved my problem.

Upvotes: 0

Quentin
Quentin

Reputation: 944206

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

Upvotes: 2

Related Questions