-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
JSON files (and other types of dependencies different from JS modules) should not be passed to acorn
to be parsed
#4
Comments
Workaround for 11ty/eleventy-dependency-tree-esm#4
I believe I've encountered this issue as well using import attributes in In a bare bones project,
❗ This only seems to happen when the imported JSON file is a non-empty object. An empty object ( Reproducible Test Case
{
"name": "eleventy-import-attributes-test",
"type": "module",
"devDependencies": {
"@11ty/eleventy": "3.0.1-alpha.1"
}
}
import app from "./app.json" with { type: "json" };
export default async function(eleventyConfig) {}
{ "name": "eleventy-import-attributes-test" }
|
Working my way through the test suite and the structure of import eleventyPackage from "./imported.json" with { type: 'json' }; …the resulting
What I think we care about is the
This is Acorn's representation of When encountering a I don't have a solution yet, but there'll need to be some updates in |
Howdy y’all! Confirmed that this is a bug with our package here. The fix will go up with |
This will roll up with Eleventy v3.0.1-alpha.2 |
You can also |
@zachleat Hero! Thanks for the fix. I’ll give it a try later tonight or tomorrow. |
Follow up: Got this working great on an Eleventy v3.0.0 project by deleting Works like a charm! // eleventy.config.js
import manifest from "./src/manifest.webmanifest.json" with { type: "json" };
export default function(eleventyConfig) {
eleventyConfig.addGlobalData("app", manifest);
// etc. etc. etc.
} |
I stumbled upon this issue while trying to fix the watch mode in one of the projects built with Eleventy.
For now, we pass the contents of such files to
acorn.parse()
:eleventy-dependency-tree-esm/main.js
Line 40 in 68687ba
acorn
, in its turn, throws theSyntaxError: Unexpected token
error (as far as I understand,acorn
tries to parse the file content as a JS statement but fails).Because of this error, the watch mode is still broken even in Eleventy
v3.0.1-alpha.1
. 😔You can see the issue in action by replacing the test in
test/stubs/imported.json
, for example, with this one:There still might be a chance that I'm missing something.
The text was updated successfully, but these errors were encountered: