Amplify-cli: Cannot read property 'length' of undefined

Created on 29 Sep 2019  路  21Comments  路  Source: aws-amplify/amplify-cli

Just updated amplify cli, and when i run 'amplify push' it starts and then gives this error:

Cannot read property 'length' of undefined
An error occured during the push operation: Cannot read property 'length' of undefined

I have simply added a string field to one of my models.

graphql-transformer pending-response pending-triage

Most helpful comment

@divait I tried doing the same with this schema and I'm not able to reproduce it. Could you email us your project?
[email protected]

I think it might not be reproducible.

I'd used version 1.12 and when I tried to update 3.15, I had same error.

So I tried to upgrade version one by one, and until version 3.2.0 there was no problem, but multi-auth was not working as expected.

3.2.0 to version 3.3.0 : there happened to be another error,
3.3.0 to version 3.4.0 : 'length' of undefined...

so I decided to go back to version 3.2.0 and delete all @key annotations with queryField and upgraded directly to version 3.15.0, and there was no 'amplify push' problem except some @connection error which could be resolved easily.

and at version 3.15.0
I re-added one @key annotation which I'd deleted before and 'amplify push' , added another @key annotation and 'amplify push'... and so on..
finally there is no "'length' of undefined" error when trying to push api, but schema.graphql is totally as same as before.

All 21 comments

If you do not paste your code change people are unable to help

@YikSanChan I changed this model:

type City @model 
@key(name: "cityByName", fields: ["title"], queryField: "findCityByName")
  @auth(rules: [
    { allow: groups, groups: ["admin"], operations: [update, delete, create] }
  ])
@searchable {
  id: ID!
  title: String!
  description: String
  country: String
  continent: String
  location: Location
  timezoneOffset: Float
  currency: String <-- NEW
  images: [String]
  createdAt: Float!
  updatedAt: Float!
}

Nothing I can see there should be causing an issue. Everything worked find before the update

if you run amplify mock api do you get error? this is an easier way to see how things go without pushing it

@YikSanChan jus did that, and get the same error:

Failed to start API Mock endpoint TypeError: Cannot read property 'length' of undefined

Its seems I cannot just update amplify cli as each time a brand new issue appears with errors that provide no idea of whats causing it

@oliverandersencox

  • Does the CLI any error stack trace for this?
  • What version of the CLI are you using?
  • Could you test if this happens in a new environment?

I am getting this as well...mock and push not working...

The following types do not have '@auth' enabled. Consider using @auth with @model
- TNSeries
- TNSermon
- Blog
- News
- Event
- Group
- Organization
- Staff
- Region
Learn more about @auth here: https://aws-amplify.github.io/docs/cli-toolchain/graphql#auth

Failed to start API Mock endpoint TypeError: Cannot read property 'length' of undefined

Using 3.11.0, update was from 3.2.0

I did update on functions, api, hosting...I have one graph and one rest api....did not resolve the issue...only change to api was to adding whitespace. API_KEY as default and AWS_IAM for additional...but only on GraphAPI...on rest it is read only for auth and guest.

I have the same issue: Update from 3.2 to 3.11 and when I update my Graphql adding a new row in one type run amplify push, get:

Cannot read property 'length' of undefined

I'm working in a windows 10.

any solution or work around?

@GeorgeBellTMH @divait What are the steps done that led up to this issue?
I'm not able to reproduce this issue below are the steps taken to reproduce this.
Using @oliverandersencox's schema with Location type defined.

Schema

type City @model
    @key(name: "cityByName", fields: ["title"], queryField: "findCityByName")
    @auth(rules: [
        { allow: groups, groups: ["admin"], operations: [update, delete, create] }
    ])
{
    id: ID!
    title: String!
    description: String
    country: String
    continent: String
    location: Location # used a some Location type
    timezoneOffset: Float
    currency: String # did not add this with the first push using ver 3.2.0
    images: [String]
    createdAt: Float!
    updatedAt: Float!
}

type Location {
    name: String!
    address: String!
}

Steps Taken

  1. Did the push with the following schema above using amplify 3.2.0.
  2. Installed amplify version 3.11.0 and added currency: String and ran mock

I get the same error:

  1. Upgrade
  2. Run push successfully
  3. Run mock (length error shows)
  4. Run push (length error shows)

Went through older versions.

Issue disappears in : npm i -g @aws-amplify/[email protected]

Ran into this error in 3.4.0:

Must provide at least one transformer. An error occured during the push operation: Must provide at least one transformer.

Downgraded to 2.0.0:

Ran into this issue: https://github.com/aws-amplify/amplify-cli/issues/2287

Renamed my keys.

Won't be upgrading again in a hurry.

In sanity-check.js line 226
var innerDiffs = deep_diff_1.diff(oldIndexesDiffable, newIndexesDiffable);
is returning null...error is happening at line 229
for (var _i = 0, innerDiffs_2 = innerDiffs; _i < innerDiffs_2.length; _i++) {

old/new index are:
OLD:

{
  'gsi-SeriesSermons': {
    IndexName: 'gsi-SeriesSermons',
    KeySchema: [ [Object] ],
    Projection: { ProjectionType: 'ALL' },
    ProvisionedThroughput: { 'Fn::If': [Array] }
  },
  BySermonIdent: {
    IndexName: 'BySermonIdent',
    KeySchema: [ [Object] ],
    Projection: { ProjectionType: 'ALL' },
    ProvisionedThroughput: { 'Fn::If': [Array] }
  }
}

NEW:

{
  BySermonIdent: {
    IndexName: 'BySermonIdent',
    KeySchema: [ [Object] ],
    Projection: { ProjectionType: 'ALL' },
    ProvisionedThroughput: { 'Fn::If': [Array] }
  },
  'gsi-SeriesSermons': {
    IndexName: 'gsi-SeriesSermons',
    KeySchema: [ [Object] ],
    Projection: { ProjectionType: 'ALL' },
    ProvisionedThroughput: { 'Fn::If': [Array] }
  }
}

I believe that after the keyBy we need to sortBy indexName for a more accurate diff...

This was resolved by deleting my global node_modules and project node_modules and reinstalling everything.

To generate the error I create my schema using version 3.2:

scalar AWSDateTime

enum DownloadType
{
  all
  reviewed
}

type Image
  @model
  @key(name: "ByDataset", fields: ["imageDatasetId", "createdAt"], queryField: "imagesByDataset")
{
  id: ID!
  key: String!
  url: String!
  status: Status!
  createdAt: AWSDateTime
  imageDatasetId: String
  width: Int!
  height: Int! 
  type: DownloadType
}

Then amplify push this works correctly.

Then I run npm install -g @aws-amplify/cli to get last version of the Amplify CLI and modify the enum:

enum DownloadType
{
  all
  labeled
  reviewed
}

And now again amplify push and get the error:

脳 An error occurred when pushing the resources to the cloud
Cannot read property 'length' of undefined
An error occured during the push operation: Cannot read property 'length' of undefined

Encountered this earlier today, had an amplify project, Then I ran npm install -g @aws-amplify/cli only to find that i could no longer amplify push.

I was too impatient to debug, but one thing is sure, the problem lies in the templates generated with the previous amplify cli version used. I backed up my project folder, removed the api category and push works. Adding the api category back makes it work just fine also.

Note: this isn't a solution, just a quick workaround

Had this issue on 3.15.0, downgraded to 3.2.0 then back to normal. I wanted to use multi auth feature but would wait until it is settled..

@divait I tried doing the same with this schema and I'm not able to reproduce it. Could you email us your project?
[email protected]

@divait I tried doing the same with this schema and I'm not able to reproduce it. Could you email us your project?
[email protected]

I think it might not be reproducible.

I'd used version 1.12 and when I tried to update 3.15, I had same error.

So I tried to upgrade version one by one, and until version 3.2.0 there was no problem, but multi-auth was not working as expected.

3.2.0 to version 3.3.0 : there happened to be another error,
3.3.0 to version 3.4.0 : 'length' of undefined...

so I decided to go back to version 3.2.0 and delete all @key annotations with queryField and upgraded directly to version 3.15.0, and there was no 'amplify push' problem except some @connection error which could be resolved easily.

and at version 3.15.0
I re-added one @key annotation which I'd deleted before and 'amplify push' , added another @key annotation and 'amplify push'... and so on..
finally there is no "'length' of undefined" error when trying to push api, but schema.graphql is totally as same as before.

@divait I tried doing the same with this schema and I'm not able to reproduce it. Could you email us your project?
[email protected]

I think it might not be reproducible.

I'd used version 1.12 and when I tried to update 3.15, I had same error.

So I tried to upgrade version one by one, and until version 3.2.0 there was no problem, but multi-auth was not working as expected.

3.2.0 to version 3.3.0 : there happened to be another error,
3.3.0 to version 3.4.0 : 'length' of undefined...

so I decided to go back to version 3.2.0 and delete all @key annotations with queryField and upgraded directly to version 3.15.0, and there was no 'amplify push' problem except some @connection error which could be resolved easily.

and at version 3.15.0
I re-added one @key annotation which I'd deleted before and 'amplify push' , added another @key annotation and 'amplify push'... and so on..
finally there is no "'length' of undefined" error when trying to push api, but schema.graphql is totally as same as before.

This work around was the way to make it work!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apanagos picture apanagos  路  47Comments

plaa picture plaa  路  60Comments

mikeparisstuff picture mikeparisstuff  路  48Comments

rygo6 picture rygo6  路  43Comments

janhesters picture janhesters  路  78Comments