photogabble / eleventy-plugin-interlinker

Adds wikilink and wikilink embed support with tracking of backlinks.
https://photogabble.co.uk/projects/eleventyjs-interlink-plugin/
MIT License
17 stars 1 forks source link

`(page.data.aliases ?? []).reduce is not a function (via TypeError)` #16

Closed xplosionmind closed 4 months ago

xplosionmind commented 7 months ago

Below is the complete log. The source is the same as https://github.com/xplosionmind/tommi.space/tree/interlinker

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] (page.data.aliases ?? []).reduce is not a function (via TypeError)
[11ty] 
[11ty] Original error stack trace: TypeError: (page.data.aliases ?? []).reduce is not a function
[11ty]     at /home/tommi/tommi.space/node_modules/.pnpm/@photogabble+eleventy-plugin-interlinker@1.0.5_@11ty+eleventy@2.0.1/node_modules/@photogabble/eleventy-plugin-interlinker/index.js:147:57
[11ty]     at Array.find (<anonymous>)
[11ty]     at /home/tommi/tommi.space/node_modules/.pnpm/@photogabble+eleventy-plugin-interlinker@1.0.5_@11ty+eleventy@2.0.1/node_modules/@photogabble/eleventy-plugin-interlinker/index.js:143:35
[11ty]     at Array.map (<anonymous>)
[11ty]     at /home/tommi/tommi.space/node_modules/.pnpm/@photogabble+eleventy-plugin-interlinker@1.0.5_@11ty+eleventy@2.0.1/node_modules/@photogabble/eleventy-plugin-interlinker/index.js:143:14
[11ty]     at Array.forEach (<anonymous>)
[11ty]     at Object.backlinks (/home/tommi/tommi.space/node_modules/.pnpm/@photogabble+eleventy-plugin-interlinker@1.0.5_@11ty+eleventy@2.0.1/node_modules/@photogabble/eleventy-plugin-interlinker/index.js:135:16)
[11ty]     at ComputedData._setupDataEntry (/home/tommi/tommi.space/node_modules/.pnpm/@11ty+eleventy@2.0.1_supports-color@9.4.0/node_modules/@11ty/eleventy/src/ComputedData.js:90:25)
[11ty]     at ComputedData.processRemainingData (/home/tommi/tommi.space/node_modules/.pnpm/@11ty+eleventy@2.0.1_supports-color@9.4.0/node_modules/@11ty/eleventy/src/ComputedData.js:111:16)
[11ty]     at Template.resolveRemainingComputedData (/home/tommi/tommi.space/node_modules/.pnpm/@11ty+eleventy@2.0.1_supports-color@9.4.0/node_modules/@11ty/eleventy/src/Template.js:625:31)
[11ty] Benchmark    489ms  29%  2262× (Configuration) "slugify" JavaScript Function
[11ty] Copied 14 files / Wrote 0 files in 1.13 seconds (v2.0.1)
 ELIFECYCLE  Command failed with exit code 1.
timklapdor commented 5 months ago

Did you find a fix for this? I'm having the same issue.

timklapdor commented 5 months ago

I went into the code and swapped the following:

const aliases = (page.data.aliases ?? []).reduce(function(set, alias){
    set.add(opts.slugifyFn(alias));
    return set;
}, new Set());

For

const aliases = ((page.data.aliases && Array.isArray(page.data.aliases)) ? page.data.aliases : []).reduce(function(set, alias){
    set.add(opts.slugifyFn(alias));
    return set;
}, new Set());

Seems to have fixed the issue.

carbontwelve commented 4 months ago

Thankyou both, unsure how I missed this issue for the past four months but I have merged Tim's fix into v1.0.6.