WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

TypeError: Cannot destructure property 'configurable' of 'descriptor' as it is undefined.

Open sidferreira opened this issue 2 years ago • 10 comments

When I try to use my models in jest tests, the use of @lazy triggers this error.

Note that I use typescript on my models.

I noticed that lazy doesn't use the makeDecorator call as other decorators use... may this be the reason?

sidferreira avatar Jun 07 '22 16:06 sidferreira

https://github.com/Nozbe/WatermelonDB/blob/4e7abb5ccbdccc018d657673ccc2c72ae06d0681/src/decorators/lazy/index.js#L15

https://github.com/Nozbe/WatermelonDB/blob/4e7abb5ccbdccc018d657673ccc2c72ae06d0681/src/decorators/date/index.js#L22

sidferreira avatar Jun 09 '22 18:06 sidferreira

How to use it then? Did you resolve the issue?

castroCrea avatar Aug 24 '22 14:08 castroCrea

@castroCrea I switched from ts-jest to babel and it fixed the issue.

sidferreira avatar Aug 24 '22 15:08 sidferreira

I am moving to a monorepo and after moving my models to a common package I am getting the same error. The package is compiled with the babel plugins that are mentioned in the installation. Any ideas what could be causing it?

{
    "presets": ["@babel/react", "@babel/preset-env"],
    "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/plugin-proposal-class-properties", { "loose": true }],
        [
            "@babel/plugin-transform-runtime",
            {
                "helpers": true,
                "regenerator": true
            }
        ]
    ],
    "targets": { "esmodules": true }
}

paul-rchds avatar Feb 07 '23 12:02 paul-rchds

Why is this closed? I'm having the same issue with NextJS which uses SWC compiler

reyalpsirc avatar Mar 28 '23 08:03 reyalpsirc

@reyalpsirc have you resolved the issue? I've faced the same issue

1755 avatar Aug 18 '23 14:08 1755

@reyalpsirc have you resolved the issue? I've faced the same issue

No, I stopped using Watermelondb with NextJS on the project I was starting. The only other solution is to avoid using the lazy decorator

reyalpsirc avatar Aug 18 '23 14:08 reyalpsirc

Still running into this issue when trying to run import a model with a @lazy decorator in a Node script. Also a monorepo setup.

/node_modules/@nozbe/watermelondb/decorators/lazy/index.js:16
    configurable: configurable,
                  ^
TypeError: Cannot destructure property 'configurable' of 'descriptor' as it is undefined.
    at lazy (/node_modules/@nozbe/watermelondb/decorators/lazy/index.js:16:19)

All my node script is doing is trying to import a model with a @lazy decorator.

@radex is there something else that needs to be done to get this working with Node? I've followed the Node setup guide already.

garygcchiu avatar Jan 16 '24 20:01 garygcchiu

For others coming across this issue, I was able to get a workaround by changing how I set up my @lazy methods:

Instead of:

@lazy commenters = this.collections.get('users').query(
    Q.on('comments', 'post_id', this.id)
)

Do:

get commenters () {
     return this.collections.get('users').query(
        Q.on('comments', 'post_id', this.id)
    )
}

Note the removal of the @lazy decorator. Since TypeScript/JavaScript getters are already lazily evaluated, I think this should be OK. Any concerns with this @radex?

garygcchiu avatar Jan 16 '24 21:01 garygcchiu