Skip to content

🐛 TypeError from unhandled undefined in eleventy plugin #1110

@aarongoldenthal

Description

@aarongoldenthal

Prerequisites

Reproduction url

https://gitlab.com/aarongoldenthal/aarongoldenthal (sorry, not a minimal reproduction, but the issue and fix is below)

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

In some cases, running knip on an eleventy project fails with the following error (this is the Alpine Linux output, but occurs on Win 11 as well)

$ knip
file:///usr/local/lib/node_modules/knip/dist/plugins/eleventy/index.js:19
    const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats;
                                        ^
TypeError: Cannot read properties of undefined (reading 'templateFormats')
    at Object.resolveConfig (file:///usr/local/lib/node_modules/knip/dist/plugins/eleventy/index.js:19:41)
    at async runPlugin (file:///usr/local/lib/node_modules/knip/dist/WorkspaceWorker.js:276:40)
    at async WorkspaceWorker.runPlugins (file:///usr/local/lib/node_modules/knip/dist/WorkspaceWorker.js:319:13)
    at async build (file:///usr/local/lib/node_modules/knip/dist/graph/build.js:94:35)
    at async main (file:///usr/local/lib/node_modules/knip/dist/index.js:[43](https://gitlab.com/aarongoldenthal/aarongoldenthal/-/jobs/10184307712#L43):88)
    at async run (file:///usr/local/lib/node_modules/knip/dist/cli.js:26:111)
    at async file:///usr/local/lib/node_modules/knip/dist/cli.js:111:1
Node.js v22.16.0

The issue is in line

const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats;
of the plugin. The error occurs when localConfig is undefined, and this line is the one that doesn't handle that.

The following change resolved the issue.

-  const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats;
+  const templateFormats = localConfig?.templateFormats || defaultEleventyConfig.templateFormats;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions