11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.19k stars 494 forks source link

v2.0.0-canary.16: `this.mdLib.disable` is not a function #2613

Closed MangelMaxime closed 1 year ago

MangelMaxime commented 2 years ago

Describe the bug

I am using remark as the markdown library via eleventy-plugin-remark.

When running my project against v2.0.0-canary.16, I get this error

> start
> cross-env ELEVENTY_ENV=dev npx @11ty/eleventy --serve

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] this.mdLib.disable is not a function (via TypeError)
[11ty] 
[11ty] Original error stack trace: TypeError: this.mdLib.disable is not a function
[11ty]     at Markdown.setLibrary (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/Engines/Markdown.js:28:16)
[11ty]     at new Markdown (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/Engines/Markdown.js:11:10)
[11ty]     at TemplateEngineManager.getEngine (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateEngineManager.js:92:20)
[11ty]     at TemplateRender.getEngineByName (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateRender.js:62:50)
[11ty]     at TemplateRender.init (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateRender.js:82:25)
[11ty]     at TemplateRender.get engine [as engine] (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateRender.js:99:12)
[11ty]     at Template.get engine [as engine] (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateContent.js:80:32)
[11ty]     at Template.getInputContent (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateContent.js:167:15)
[11ty]     at Template.read (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateContent.js:108:38)
[11ty]     at Template.getFrontMatterData (/Users/mmangel/Workspaces/Github/MangelMaxime/mangelmaxime.github.io/node_modules/@11ty/eleventy/src/TemplateContent.js:210:18)

To Reproduce Steps to reproduce the behavior:

  1. Change the Markdown library to eleventyRemark
const eleventyRemark = require("@fec/eleventy-plugin-remark");

module.exports = function (eleventyConfig) {

    eleventyConfig.addPlugin(eleventyRemark);

    // set input and output folder
    return {
        dir: {
            input: ".",
            includes: "_includes",
            data: "_data",
            output: "_site",
        },
        dataTemplateEngine: "njk",
        htmlTemplateEngine: "njk",
        markdownTemplateEngine: "njk",
    };
};
  1. Run eleventy against your project
  2. See error

Expected behavior A clear and concise description of what you expected to happen.

The project should compile.

Screenshots If applicable, add screenshots to help explain your problem.

Environment:

Additional context

I think the problem is coming from this line:

https://github.com/11ty/eleventy/blob/30fd4c5d823fc047c66c3f79cab1303caaa1e93b/src/Engines/Markdown.js#L28

Related to:

Starting in Eleventy 2.0, we’ve disabled the Indented Code Blocks feature by default.

Does that means that now when the markdown library is overwritten the new library needs to probide disable and enable functions?

Should eleventy only try to call these functions, if they exist?

pdehaan commented 2 years ago

/cc @zachleat

NickColley commented 2 years ago

Work around is to set the function to a noop:

eleventyConfig.setLibrary("md", {
    disable: () => {},
    render: (content) => markdown(content),
});
MangelMaxime commented 2 years ago

@NickColley Indeed,

I manually modified the file in the node modules (just temporary ^^). And for a complete workaround, enable should also be set to noop.

zachleat commented 1 year ago

Thank you @NickColley! This fix will ship with 2.0.0-canary.18!