Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.11ty.cjs extension not recognized as JavaScript template #826

Closed
justinfagnani opened this issue Dec 19, 2019 · 5 comments · Fixed by #827
Closed

.11ty.cjs extension not recognized as JavaScript template #826

justinfagnani opened this issue Dec 19, 2019 · 5 comments · Fixed by #827

Comments

@justinfagnani
Copy link
Contributor

Describe the bug
I have a project that has to have "type": "module" in its package.json. For other tools simply changing configuration/plugin scripts to have a .cjs extension has worked. Templates with .11ty.cjs don't work for eleventy however as that extension isn't recognized as a JavaScript template type.

To Reproduce
Steps to reproduce the behavior:

  1. Create a _includes/home.11ty.cjs template file
  2. Add layout: home.11ty.cjs to a content file
  3. Run eleventy
  4. See error

Expected behavior
_includes/home.11ty.cjs is treated as a JavaScript template

Screenshots

The error:

> Unknown engine for docs-src/_includes/home.11ty.cjs

`TemplateRenderUnknownEngineError` was thrown:
    TemplateRenderUnknownEngineError: Unknown engine for docs-src/_includes/home.11ty.cjs

Environment:

  • macOS 10.14
  • Eleventy Version 0.9.0
@zachleat
Copy link
Member

What are the ramifications of this? Is this still accurate? https://2ality.com/2019/04/nodejs-esm-impl.html#filename-extensions

If so it would seem like we should add both .mjs and .cjs right?

@justinfagnani
Copy link
Contributor Author

The thing with .mjs extensions is that they must be imported and not required. That'll be a bigger change, and only work on Node >= 13.2, and probably will require using dynamic import since eleventy is written in CJS. Dynamic import means that code path has to be async. It might be already, but just knowing it was a much larger task I didn't even take a look.

@zachleat
Copy link
Member

Sorry for all the questions, I’m pretty sure I’m totally on board with this but I’m a little new to the modules discussion and familiarizing myself. If you have any good resources to share I would greatly appreciate them!

So you’re using "type": "module" with your existing project? Isn’t that also Node 12+ with --experimental-modules or Node 13+ only? Is there some other transpilation happening?

Also thinking ahead a little bit, it seems like additional work will probably need to be done if I want Eleventy to support ESM templates by default (or with .mjs files) and whether that even makes sense for our current Node compatibility. Filed this at #836.

@zachleat
Copy link
Member

Added a few additional TODOs for this task at #837

@justinfagnani
Copy link
Contributor Author

No worries on the modules questions. I happen to know a lot of the details from a lot of different projects, so I'm a good one to ask :) I'll take it to #837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants