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

Running Eleventy with DEBUG set breaks when using ES Modules #2129

Closed
j-f1 opened this issue Dec 3, 2021 · 4 comments
Closed

Running Eleventy with DEBUG set breaks when using ES Modules #2129

j-f1 opened this issue Dec 3, 2021 · 4 comments
Assignees
Labels
bug: dependency A problem in one of Eleventy’s dependencies

Comments

@j-f1
Copy link
Contributor

j-f1 commented Dec 3, 2021

Describe the bug
While Eleventy doesn’t support using ES Modules directly (i.e. as a config file or within _data/, ref. #836), it’s still possible to use dynamic import() syntax in CommonJS modules on recent Node.js versions. This is necessary to use ESM-only packages.

When the DEBUG environment variable is set, Eleventy requires the time-require package, which was last updated in 2014. It overrides Module._load to calculate timing information. This is called when requiring or importing a CommonJS module. time-require assumes that _load will be passed a module name and a parent. When ESM code tries to import a CommonJS module, Module._load is called with parent set to undefined. This results in a crash.

To Reproduce
Steps to reproduce the behavior:

  1. In an Eleventy project, install camelcase
  2. In your Eleventy config file, call import("camelcase")
  3. run DEBUG='Eleventy:Benchmark*' npx @11ty/eleventy
  4. See error

Expected behavior
No error, ideally helpful timing information is displayed for ES modules in addition to CommonJS ones.

Environment:

  • OS and Version: macOS 11.6 (20G165)
  • Eleventy Version 1.0.0-beta.8

Additional context
Ideally, either the time-require package would be forked, patched, and updated to work better with ES Modules.

As an alternative, it would be great to make the time-require import explicitly opt-in, allowing analysis of CJS-only projects without breaking perf debugging for CJS+ESM projects.

@zachleat
Copy link
Member

Okay resolution if we remove time-require entirely? I don’t get a ton of value out of it, personally.

@zachleat zachleat self-assigned this Dec 19, 2021
@zachleat
Copy link
Member

I went ahead and removed it, you can try that out in 1.0.0-canary.48

@j-f1
Copy link
Contributor Author

j-f1 commented Dec 20, 2021

It looks like that works! Thanks :)

@zachleat zachleat added this to the Eleventy 1.0.0 milestone Dec 27, 2021
@zachleat zachleat added bug: dependency A problem in one of Eleventy’s dependencies and removed needs-triage labels Dec 27, 2021
@zachleat
Copy link
Member

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: dependency A problem in one of Eleventy’s dependencies
Projects
None yet
Development

No branches or pull requests

2 participants