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.

Create React App: Cannot read property 'startsWith' of undefined

See original GitHub issue

Hi,

I’m using graphql.macro@1.3.5 with create-react-app@16.8, and when I try to import loader from graphql.macro, it throws me this:

TypeError: graphql.macro: Cannot read property 'startsWith' of undefined Learn more: https://www.npmjs.com/package/graphql.macro
    at Array.forEach (<anonymous>)
    at Array.forEach (<anonymous>)

I’m not really sure how to setup babel macros, so I may have forgotten a dependency (by the way, is graphql really needed?).

Here’s my config:

package.json

{
  ...
  "dependencies": {
    ...
    "graphql": "^14.2.1",
    "graphql-request": "^1.8.2",
    "graphql.macro": "^1.3.5",
    "react": "^16.8.5",
    "react-scripts": "2.1.8",
    "typescript": "3.3.4000"
    ...
  },
  ...
}

.babelrc

{
  "plugins": ["graphql.macro"]
}

src/components/App.tsx

...
import {loader} from 'graphql.macro';
console.log(loader); // the error is thrown at this point
...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
jissereitsmacommented, Jul 29, 2019

I’ve bumped into the same error. However, it seems that there is some magic going on during compilation that throws this error. Do not try to dump loader to the console. Do you get the same error when you are simply using the loader, i.e. loader("./path/to/some.graphql")?

In my case, I’m getting no error when using loader("./path/to/some.graphql") but the error only appears as soon as I’m creating a new variable const myGraphQlFile = "./path/to/some/graphql"; loader(myGraphQlFile);.

0reactions
biggytechcommented, Aug 24, 2022

Same here, happening when I try to use path to file from a variable. I’d wanted to load a bunch of graphql-files from an array, but it doesn’t allow that 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property startsWith of undefined
console.log your this.props.description variable. The only way this error will appear is if it has no value. The reason everything works fine in ......
Read more >
Cannot read property 'startsWith' of undefined #354 - GitHub
I installed the library and linked it with react-native link react-native-fs. I try to run the minimal example: RNFS.readDir(RNFS.
Read more >
TypeError: Cannot read property 'startsWith' of undefined
Hi, im trying to connect to MongoAtlas run an app that uses mongodb (^4.3.1 ) in nodejs (version 10.19.0), Windows 7 & then...
Read more >
TypeError: Cannot read property 'startsWith' of undefined
it means you are calling startsWith(...) on a variable that is undefined somewhere in your function. ... PS, I assume that's not the...
Read more >
Vue3 Cannot read property 'startsWith' of undefined - Laracasts
Hi, I'm trying to setup laravel 8, vue 3, inertia, bootstrap 5. I was getting all sort of errors I figured somehow mainly...
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