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

Eleventy templates esm related errors are rather unhelpful #3571

Closed
thoughtsunificator opened this issue Dec 5, 2024 · 6 comments
Closed
Assignees

Comments

@thoughtsunificator
Copy link

thoughtsunificator commented Dec 5, 2024

Operating system

Linux

Eleventy

3.0.0

Node

Node.js v24.0.0-pre

Describe the bug

A template file, foo.11ty.js with the following code:

export const

yields:

[11ty] Problem writing Eleventy templates:
[11ty] Unexpected end of input (via SyntaxError)
[11ty] 
[11ty] Original error stack trace: SyntaxError: Unexpected end of input
[11ty]     at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
[11ty]     at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:103:18)
[11ty]     at #translate (node:internal/modules/esm/loader:437:12)
[11ty]     at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:484:27)
[11ty]     at async ModuleJob._link (node:internal/modules/esm/module_job:115:19)
[11ty] Wrote 0 files in 0.03 seconds (v3.0.0)

The problem is that there are no clear indicators as to the origins of the error.

Reproduction steps

Assuming linux and bash:

[foo@bar ~]$ echo "export const" > /tmp/foo.11ty.js && npx @11ty/eleventy@3.0.0 --input=/tmp/foo.11ty.js

Expected behavior

I should be getting a real indicator as to the origins of the error.

Reproduction URL

No response

Screenshots

No response

@thoughtsunificator thoughtsunificator changed the title Eleventy templates import system errors are unhelpful Eleventy templates esm related errors are unhelpful Dec 5, 2024
@thoughtsunificator
Copy link
Author

thoughtsunificator commented Dec 5, 2024

This is what you'd be getting running the file directly:

[foo@bar ~]$ node /tmp/foo.11ty.js 
file:///tmp/foo.11ty.js:2

SyntaxError: Unexpected end of input
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:103:18)
    at #translate (node:internal/modules/esm/loader:437:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:484:27)
    at async ModuleJob._link (node:internal/modules/esm/module_job:115:19)

Node.js v24.0.0-pre

@thoughtsunificator
Copy link
Author

thoughtsunificator commented Dec 5, 2024

The same problem also occurs with:

[foo@bar ~]$ echo "foo" > /tmp/foo.11ty.js && npx @11ty/eleventy@3.0.0 --input=/tmp/foo.11ty.js

@thoughtsunificator
Copy link
Author

Even worse if your eleventy config contains invalid syntax such as:

import foo from "./bar" with { type: "json" }

[11ty] 1. A problem was encountered looking for JavaScript dependencies in ESM file: ./eleventy.config.js. This only affects --watch and --serve behavior and does not affect your build. (via EleventyBaseError)
[11ty] 2. Unexpected token (2:7) (via SyntaxError)

@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Dec 6, 2024

Reminds me on #3491.
That is, perhaps the issue is with Acorn that Eleventy is using under the hood.

REPL shows the same behavior

(Acorn doesn't understand with yet)

@thoughtsunificator thoughtsunificator changed the title Eleventy templates esm related errors are unhelpful Eleventy templates esm related errors are rather unhelpful Dec 7, 2024
@zachleat
Copy link
Member

Related #3580

@zachleat zachleat added this to the Eleventy 3.0.1 milestone Dec 12, 2024
@zachleat zachleat self-assigned this Dec 12, 2024
@zachleat
Copy link
Member

Error messaging will show file path in v3.0.1-alpha.1—thank you!

[11ty] Problem writing Eleventy templates:
[11ty] 1. There was a problem importing 'foo.11ty.js' via import(esm) (via EleventyImportError)
[11ty] 2. Unexpected end of input (via SyntaxError)
[11ty] 
[11ty] Original error stack trace: SyntaxError: Unexpected end of input
[11ty]     at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
[11ty]     at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:102:18)
[11ty]     at #translate (node:internal/modules/esm/loader:437:12)
[11ty]     at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:484:27)
[11ty]     at async ModuleJob._link (node:internal/modules/esm/module_job:115:19)
[11ty] Wrote 0 files in 0.02 seconds (v3.0.1-alpha.1)

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

No branches or pull requests

3 participants