TypeError: Cannot read properties of undefined (reading 'id')
Zerotask opened this issue · 7 comments
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
3.20.1
Plugin version
7.2.2
Node.js version
16.9
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10
Description
I tried adding CSRF protection as described here: https://docs.nestjs.com/security/csrf#use-with-fastify
Then I run: npm run start:dev
Before accessing a route, I got the following errors:
C:\Users\Patrick\dev\nastyville-testing\node_modules\avvio\time-tree.js:40
if (parentNode.id) {
TypeError: Cannot read properties of undefined (reading 'id')
at TimeTree.getParent (C:\Users\Patrick\dev\nastyville-testing\node_modules\avvio\time-tree.js:40:18)
at TimeTree.add (C:\Users\Patrick\dev\nastyville-testing\node_modules\avvio\time-tree.js:63:27)
at TimeTree.start (C:\Users\Patrick\dev\nastyville-testing\node_modules\avvio\time-tree.js:78:15)
at Plugin. (C:\Users\Patrick\dev\nastyville-testing\node_modules\avvio\boot.js:245:36)
at Object.onceWrapper (node:events:514:26)
at Plugin.emit (node:events:394:28)
Steps to Reproduce
See description.
Expected Behavior
No error
Maybe this is already fixed, since 7.2.2 is not the latest version. Then please transfer this to https://github.com/fastify/fastify-csrf which is the initiator.
We do not officially support Nest.js. Can you please provide an example that just use fastify/fastify-csrf standalone?
8.1.0 - The same error.
Is not about NestJs. Nest can use different engines, and in this particular case we use fastify. But fastify is dependent to avvio.
Thanks for reporting. We do not have the resources to support Nest.js users. Please refer to the Nest Discord channel (support) for such questions.
In case you think it's a bug in avvio, please try to reproduce the problem with avvio only. Thanks.
Maybe this is already fixed, since 7.2.2 is not the latest version. Then please transfer this to https://github.com/fastify/fastify-csrf which is the initiator.
I solved error handling parentNode.id, because parentNode in my app is undefined, and you can't get the id of parentNode.
file node_modules\fastify\node_modules\avvio\time-tree.js (34 - 45)
TimeTree.prototype.getParent = function (parent) {
if (parent === null) {
return this.root
}
const parentNode = this.tableLabel.get(parent)
if (parentNode?.id) {
return parentNode
}
return parentNode ? parentNode[parentNode?.length - 1] || null : null
}
Below sample can reproduce this problem with avvio@8.2.1
:
const app = require('avvio')()
app.use(function first(instance, opts, cb) {
console.log('plugins:', instance.prettyPrint())
cb()
})
Output:
plugins: bound root undefined ms
└── first undefined ms
/Users/xuxucode/projects/avvio-sample/node_modules/avvio/time-tree.js:31
if (labelNode.id) {
^
TypeError: Cannot read properties of undefined (reading 'id')
at [avvio.TimeTree.untrackNode] (/Users/xuxucode/projects/avvio-sample/node_modules/avvio/time-tree.js:31:19)
at TimeTree.stop (/Users/xuxucode/projects/avvio-sample/node_modules/avvio/time-tree.js:94:25)
at Plugin.<anonymous> (/Users/xuxucode/projects/avvio-sample/node_modules/avvio/boot.js:254:23)
at Object.onceWrapper (node:events:626:26)
at Plugin.emit (node:events:511:28)
at done (/Users/xuxucode/projects/avvio-sample/node_modules/avvio/plugin.js:197:10)
at check (/Users/xuxucode/projects/avvio-sample/node_modules/avvio/plugin.js:224:9)
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
Node.js v20.1.0