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.

TypeError: Cannot read property 'typeName' of undefined

See original GitHub issue

Description

Seeing non-descriptive error (below) on gridsome build and gridsome develop.

TypeError: Cannot read property 'typeName' of undefined
    at fieldValue (.../node_modules/gridsome/lib/graphql/createFieldDefinitions.js:43:23)
    at fieldValues (.../node_modules/gridsome/lib/graphql/createFieldDefinitions.js:26:16)
    at createFieldDefinitions (.../node_modules/gridsome/lib/graphql/createFieldDefinitions.js:9:14)
    at module.exports.store (.../node_modules/gridsome/lib/graphql/nodes/index.js:14:20)
    at module.exports.store (.../node_modules/gridsome/lib/graphql/createSchema.js:7:41)
    at App.createSchema (.../node_modules/gridsome/lib/app/App.js:168:20)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Expected result

Build is successful.

Environment

package.json:

{
  "name": "siteName",
  "private": true,
  "scripts": {
    "build": "gridsome build",
    "develop": "gridsome develop",
    "explore": "gridsome explore"
  },
  "dependencies": {
    "@gridsome/source-contentful": "^0.3.0",
    "gridsome": "^0.6.4",
    "vue-showdown": "^2.4.1"
  },
  "devDependencies": {
    "gridsome-plugin-purgecss": "^1.0.12",
    "gridsome-plugin-tailwindcss": "^1.3.2"
  }
}

gridsome.config.js

module.exports = {
	siteName: 'SiteName',
	plugins: [
		{
			use: 'gridsome-plugin-tailwindcss'
		},
		{
			use: 'gridsome-plugin-purgecss'
		},
		{
			use: '@gridsome/source-contentful',
			options: {
				space: process.env.xyz,
				accessToken: process.env.xyz,
				host: 'cdn.contentful.com',
				environment: 'master',
				typeName: 'Contentful',
				routes: {
					'Tag': '/tags/:slug',
					'Article': '/articles/:slug',
					'Page': ':slug'
				}
			}
		}
	]
}

For Tooling issues:

  • Node version: v10.14.2
  • Platform: Mac

Notes:

  • Ran npm install/update today and noticed @gridsome/source-contentful had been updated today but unsure if that’s related.
  • Tried upgrading/downgrading Gridsome and Contentful in package.json

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
joranquintencommented, Jun 5, 2020

This didn’t solve my issue, since the photo was completely deleted (non recoverable). It’s not helpful that the build doesn’t give a decent pointer. For those encountering this, I’ve change lines 75:81 in the gridsome/lib/graphql/createFieldDefinitions.js (v 0.7.16) into:

      for (let i = 0; i < length; i++) {
        if (value[i] && value[i].hasOwnProperty('typeName')){
          if (!value[i].typeName) {
            warn(`Missing typeName for reference at: ${path.join('.')}.${i}`)
          } else if (!currentValue.typeName.includes(value[i].typeName)) {
            currentValue.typeName.push(value[i].typeName)
          }
        } else {
          warn(`Missing typeName property for reference at: ${path.join('.')}.${i}`)
        }
      }

Which at least points into the right direction. This way I was able to find the deleted photos which were linked in other entries.

0reactions
maximilliangeorgecommented, Jun 8, 2021

This didn’t solve my issue, since the photo was completely deleted (non recoverable). It’s not helpful that the build doesn’t give a decent pointer. For those encountering this, I’ve change lines 75:81 in the gridsome/lib/graphql/createFieldDefinitions.js (v 0.7.16) into:

      for (let i = 0; i < length; i++) {
        if (value[i] && value[i].hasOwnProperty('typeName')){
          if (!value[i].typeName) {
            warn(`Missing typeName for reference at: ${path.join('.')}.${i}`)
          } else if (!currentValue.typeName.includes(value[i].typeName)) {
            currentValue.typeName.push(value[i].typeName)
          }
        } else {
          warn(`Missing typeName property for reference at: ${path.join('.')}.${i}`)
        }
      }

Which at least points into the right direction. This way I was able to find the deleted photos which were linked in other entries.

This was a huge help and a great improvement. You should submit this as a PR. Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
TypeError: Cannot read property 'type' of undefined Error ...
Your reducer function needs order the state first and action after. const rootReducer = combineReducers({ battle: manageBattle, ...
Read more >
TypeError: Cannot read property 'typeName' of undefined - APIs
I am using GraphQL to query data from Contentful within Gridsome. After deleting a field in one of my content types I can...
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
Interpreting undefined or null as subtypes of all other types can lead to runtime problems. For example, if you try to get the...
Read more >
Cannot read properties of undefined (reading 'type') - MongoDB
I am getting an error similar to TypeError: Cannot read properties of undefined (reading 'startsWith') with a different variable but same ...
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