question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In this environment the sources for assign MUST be an object

See original GitHub issue

Hi,

Trying to use the GraphQL API with a non AppSync set up and using a server that’s been created using API Gateway and a Lambda. I can call the API perfectly fine using an ID token I’ve either generated myself or from the Auth library within AWS Amplify, but whenever trying to call the API using Amplify I get the following:

TypeError: In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant.
    at Object.assign (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:324)
    at APIClass.<anonymous> (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133915)
    at step (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133372)
    at Object.next (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133302)
    at fulfilled (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133254)
    at tryCallOne (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3732)
    at blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3833
    at blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3113
    at _callTimer (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3002)
    at _callImmediatesPass (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3038)

I do have another issue open at the moment regarding HTTP method type, but for now I’ve updated the API to allow GET requests. The code in my React Native app looks like this:

import React, { Component } from 'react';
import Amplify, { API, Auth, graphqlOperation } from 'aws-amplify';

Amplify.Logger.LOG_LEVEL = 'DEBUG';

Amplify.configure({
  API: {
    graphql_endpoint: 'https://myurl.com/graphql',
    graphql_headers: async () => {
      const { idToken } = await Auth.currentSession();
      const Authorization = idToken.getJwtToken();

      console.log('ID token:', Authorization);

      return { Authorization };
    },
  },
  Auth: {
    identityPoolId: '***,
    region: '***',
    userPoolId: '***',
    userPoolWebClientId: '***',
  }
});

export default class App extends Component {
  async componentDidUpdate() {
    if (this.props.authState !== 'signedIn') {
      return null;
    }

    try {
      const query = graphqlOperation('valid_query');
      console.log(query);
      await API.graphql(query);
    } catch (error) {
      console.log(error);
    }
  }

  render() {
    if (this.props.authState !== 'signedIn') {
      return null;
    }
    // ...
  }
}

The code has been simplified a bit, but the only thing missing is the authenticator which works perfectly fine.

My dependencies are:

  "dependencies": {
    "aws-amplify": "^1.0.8",
    "aws-amplify-react-native": "^1.0.8",
    "native-base": "^2.8.0",
    "react": "16.4.1",
    "react-native": "0.56.0"
  },

Any idea why this might be happening?

Thanks, Gary

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14

github_iconTop GitHub Comments

5reactions
demsey2commented, Sep 18, 2018

I have the same issue, did you find a solution?

I also looked at the source of that error “In this environment the target of assign MUST be an object. This error is a performance optimization and not spec compliant.”. It comes from node_modules/react-native/Libraries/polyfills/Object.es6.js

and this is a comment for that polyfill

// WARNING: This is an optimized version that fails on hasOwnProperty checks
// and non objects. It's not spec-compliant. It's a perf optimization.
// This is only needed for iOS 8 and current Android JSC.

so it looks like aws-amplify uses Object.assign properly but for some reasons that polyfill is used. I am not sure how to skip that polyfill, I don’t need to support IOS8 and Android JSC.

I checked that polyfill and it looks like it has been fixed and now is spec-compliant https://github.com/facebook/react-native/commit/966bb63a80750757dc7a78d7d1f8960a2d8e25e0#diff-cb5173a6f8d88f7801f5127b94bfc330

so anyone with the problem should upgrade to react-native 0.57 and confirm if that helps to solve the issue, in my case I use Expo and the latest supported RN is 0.55.4 so I need to wait for the next Expo release

1reaction
lissaucommented, May 10, 2019

Great. Thank you for the feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In this environment the sources for assign MUST be an ...
TypeError: In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant.
Read more >
TypeError: In this environment the sources for assign ...
This error happens because in that RNE version the iconRight prop should be an object instead of boolean. This was changed in the...
Read more >
Javascript – Error when creating new object from existing one ...
Javascript – Error when creating new object from existing one using `…`: In this environment the sources for assign MUST be an object....
Read more >
Overview of Azure Policy
Azure Policy is a service in Azure, that you use to create, assign and, manage policy definitions in your Azure environment.
Read more >
TypeError: 'x' is not iterable - JavaScript - MDN Web Docs
The non-iterable might turn to be undefined in some runtime environments. ... Instead you have to use Object.keys or Object.entries , to iterate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found