storyblok / storyblok-js-client

Universal JavaScript client for Storyblok's API
MIT License
123 stars 85 forks source link

getAll() fails with "TypeError: Cannot convert undefined or null to object" #822

Open andersekdahl opened 3 months ago

andersekdahl commented 3 months ago

When calling client.getAll('cdn/stories/', {}) it fails with:

TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at file:///C:/Dev/xxx-2/node_modules/@storyblok/js/dist/storyblok-js.mjs:583:23
    at Array.map (<anonymous>)
    at b.flatMap (file:///C:/Dev/xxx-2/node_modules/@storyblok/js/dist/storyblok-js.mjs:65:105)
    at ct.getAll (file:///C:/Dev/xxx-2/node_modules/@storyblok/js/dist/storyblok-js.mjs:579:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This seems to be because of this line: https://github.com/storyblok/storyblok-js-client/blob/5cdb067f9cde331ec9f4c7faf6505cc1643814d4/src/index.ts#L262

The data property contains an object with a property called stories but the e variable is an empty string. If I change it to e || 'stories' it seems to work.


Expected Behavior

I should get back all stories.

Current Behavior

There's an error thrown.

Steps to Reproduce

Call getAll() with these arguments: client.getAll('cdn/stories/', {})

swissmexxa commented 3 months ago

yes, same issue here.