Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'length' of undefined #3512

Closed
anilanar opened this issue Feb 15, 2020 · 7 comments
Closed

Cannot read property 'length' of undefined #3512

anilanar opened this issue Feb 15, 2020 · 7 comments

Comments

@anilanar
Copy link

anilanar commented Feb 15, 2020

My conclusion

This seems to be an issue with deep network of dependencies: globby -> fast-glob -> micromatch. At the top of the stack trace, fast-glob calls a function from micromatch:

const info = micromatch.scan(pattern, Object.assign(Object.assign({}, options), { parts: true }));
// See micromatch/picomatch#58 for more details
if (info.parts.length === 0) {
    return [pattern];
}

If you console.log(info), it has no parts property:

{
  prefix: '',
  input: 'src/umd-exchange/gql/*.graphql',
  base: 'src/umd-exchange/gql',
  glob: '*.graphql',
  negated: false,
  isGlob: true
}

The micromatch version that causes the bug is 4.0.2.
The fast-glob version that causes the bug is 3.2.0.
The globby version that causes the bug is 11.0.0.

So basically, this problem happens when everything is on their latest version.

Describe the bug

$ graphql-codegen
  ✔ Parse configuration
  ❯ Generate outputs
    ❯ Generate src/umd-exchange/gql.ts
      ✔ Load GraphQL schemas
      ✖ Load GraphQL documents
        → Cannot read property 'length' of undefined

  ✖ src/umd-exchange/gql.ts
    TypeError: Cannot read property 'length' of undefined
        at Object.getPatternParts (<omitted>/node_modules/globby/node_modules/fast-glob/out/utils/p
attern.js:94:20)
        ...

To Reproduce
Steps to reproduce the behavior:

https://codesandbox.io/s/vibrant-fire-f0x5p

  1. My GraphQL schema:
type Subscription {
  newMessage(conversationId: Int!): String!
}
schema {
  subscription: Subscription
}
  1. My GraphQL operations:
subscription onNewMessage($id: Int!) {
  newMessage(conversationId: $id)
}
  1. My codegen.yml config file:
overwrite: true
generates:
  src/umd-exchange/gql.ts:
    schema: src/umd-exchange/schema.graphql
    documents: src/umd-exchange/gql/*.graphql
    plugins:
      - typescript
      - typescript-resolvers
      - typescript-operators
      - typescript-graphql-files-modules

Expected behavior
No error.

Environment:

  • OS: MacOS
  • "@graphql-codegen/cli": "1.12.2"
  • "@graphql-codegen/introspection": "1.12.2"
  • "@graphql-codegen/typescript": "1.12.2"
  • "@graphql-codegen/typescript-document-nodes": "1.12.2"
  • "@graphql-codegen/typescript-graphql-files-modules": "1.12.2"
  • "@graphql-codegen/typescript-resolvers": "1.12.1"
  • NodeJS: 12.14.0

Additional context

@anilanar
Copy link
Author

I tried locking fast-glob to 3.1.1:

  "resolutions": {
    "fast-glob": "3.1.1"
  }

Error has gone.

@anilanar
Copy link
Author

Reported upstream: mrmlnc/fast-glob#253

@andrerpena
Copy link

@anilanar Thank you. You saved me a lot of time

@dotansimha
Copy link
Owner

@anilanar Thank you for reporting and finding a workaround!
I tried to run the reproduction sandbox - but it seems to work, can you please verify that?

@dotansimha dotansimha added the waiting-for-answer Waiting for answer from author label Feb 16, 2020
@marcomelilli
Copy link

@anilanar thank you, you saved my day. For those who use npm, I found this plugin to use "resolutions" as workaround: https://www.npmjs.com/package/npm-force-resolutions

@anilanar
Copy link
Author

anilanar commented Feb 16, 2020

TL;DR

We are waiting for a fix by micromatch, then fast-glob and globby needs to release a new version too.


@dotansimha It's kind of hard to reproduce. I had to copy my own yarn.lock and then run yarn, which updates yarn.lock again.

The specific problem is described in micromatch/micromatch#196 and in mrmlnc/fast-glob#253. So the problem only happens if node_modules had a version of picomatch between 2.0.5 and 2.2.0 before installing a dependency that requires micromatch 4.0.2.

@dotansimha
Copy link
Owner

It seems like fast-glob solved it in v3.2.1. Keeping open until fully solved.
Thanks @anilanar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants