I had this error message TypeError: Cannot read properties of undefined (reading 'length') before in my code many times before and it usually means that the you're trying to access data from an object that does not yet exist in memory.
In your code that you posted, the line that is causing the error is likely to be:
const itens = db.all().map(item => `ID: ${item.ID} | QUANTIDADE: ${item.data.conta.length || "0"}`)
Since you're not properly checking to see if it exists before outputting data. I see you're using a logical OR for this but sometimes that doesn't properly work as expected.
To fix this, replace the check with a ternary operator to see if item.data is defined before accessing its properties. You can modify the line to look something like this:
const itens = db.all().map(item => `ID: ${item.ID} | QUANTIDADE: ${item.data && item.data.conta ? item.data.conta.length : "0"}`)
This checks to see if item.data exists and if it has the conta property before accessing its length. If either of these properties is resolved as being undefined, it will default to "0".
Possible interactor return types (masks)
TypeError: Cannot read properties of undefined (reading 'length') unhandledRejection
Could not upload annotation
SAM3 integrate
I had this error message TypeError: Cannot read properties of undefined (reading 'length') before in my code many times before and it usually means that the you're trying to access data from an object that does not yet exist in memory.
In your code that you posted, the line that is causing the error is likely to be:
const itens = db.all().map(item => `ID: ${item.ID} | QUANTIDADE: ${item.data.conta.length || "0"}`)
Since you're not properly checking to see if it exists before outputting data. I see you're using a logical OR for this but sometimes that doesn't properly work as expected.
To fix this, replace the check with a ternary operator to see if item.data is defined before accessing its properties. You can modify the line to look something like this:
const itens = db.all().map(item => `ID: ${item.ID} | QUANTIDADE: ${item.data && item.data.conta ? item.data.conta.length : "0"}`)
This checks to see if item.data exists and if it has the conta property before accessing its length. If either of these properties is resolved as being undefined, it will default to "0".
First you have to used === operator so its match value and check type too.
try to replacing if condition like below:
if(db.all().length == 0 || undefined) return message.channel.send({embeds: [embednprod]}).then(msg => {
setTimeout(() => msg.delete(), 10000)
})
Receiving this error on one of my game files. All mods are turned off currently.
Currently running Version 11 Build 315
DnD5e 3.1.2
foundry.js:68326 Cannot read properties of undefined (reading 'length')
|| || ||fetch|@|foundry.js:68326| ||notify|@|foundry.js:68223| ||error|@|foundry.js:68260| ||_handleError|@|foundry.js:3468| ||(anonymous)|@|foundry.js:3450| ||value|@|socket.js:532| ||value|@|socket.js:459| ||L.emit|@|index.mjs:136| ||(anonymous)|@|manager.js:207| ||Promise.then (async)||| ||it|@|websocket-constructor.browser.js:5| ||value|@|manager.js:206| ||L.emit|@|index.mjs:136| ||value|@|index.js:131| ||value|@|manager.js:193| ||L.emit|@|index.mjs:136| ||value|@|socket.js:324| ||L.emit|@|index.mjs:136| ||value|@|transport.js:97| ||value|@|transport.js:89| ||ws.onmessage|@|websocket.js:69| ||Show less|
foundry.js:6629 TypeError: Cannot read properties of undefined (reading 'length')
at Preprocessor.advance (/data/application/re…processor.js:138:35)
at Tokenizer._consume (/data/application/re…zer/index.js:270:34)
at Tokenizer._runParsingLoop (/data/application/re…zer/index.js:221:29)
at Tokenizer.write (/data/application/re…zer/index.js:248:14)
at parseFragment (/data/application/re…dist/index.js:42:22)
at cleanHTML (/data/application/re…alidators.mjs:1:209)
at HTMLField.sanitizeHTMLField [as sanitize] (/data/application/re…tization.mjs:1:1235)
at Item._sanitizeFields (/data/application/re…document.mjs:1:7729)
at Item._sanitizeFields (/data/application/re…document.mjs:1:7956)
at Item.sanitizeUserInput (/data/application/re…document.mjs:1:7436)
|| || ||_onSubmit|@|foundry.js:6629| ||await in _onSubmit (async)||| ||_onSubmit|@|item-sheet.mjs:786| ||saveEditor|@|foundry.js:6773| ||onSave|@|item-sheet.mjs:410| ||_handleSave|@|prosemirror.js:19030| ||_onAction|@|prosemirror.js:19003| ||button.onclick|@|prosemirror.js:18504|