-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add the @babel/plugin-syntax-import-attributes
plugin to allow JSON imports with type assertion
#251
Comments
So, I have bad news. This only happens after I upgrade from packemon 4.0.1 to 4.1.0, and remove Leaving it in my dev-deps causes babel to load it twice and insert top-level awaits.
While removing it from my dev deps also removes the duplicate plugins error, the top-level awaits are still inserted.
Only one source file was triggering all of these errors:
No top-level awaits in the source, but the
This is, of course, manually resolveable by replacing the static import with a require, but that also means we can't use the import attributes to confirm it's a json module. |
Or I could save myself the headache and finally drop CJS entirely. I've been delaying that breaking change for no one's benefit. |
I'm not sure what the fix would be here without removing the plugin itself? Seems like a bug in babel itself if it's injecting await into a CJS module. |
If I find the time to do so, I'll checkout and debug my previous configuration to determine why packemon 4.0.1 with this plugin added wasn't inserting a top-level |
I also enabled this: https://babeljs.io/docs/babel-plugin-proposal-json-modules But it looks like it should support CJS. When I enabled it, all the snapshots showed the file data being resolved correctly, so there was no await used at all. https://github.com/milesj/packemon/pull/256/files What's your full config? Maybe its a certain combination causing it. |
A range of relevant commits The diff for packemon.config.ts. And the |
I only realize this now: my Packemon 4.0.1 config did not include that plugin. As it states, that plugin transforms json module imports to platform-dependent implementations instead of allowing the platform's runtime to handle the attribute. I did some debugging and found that a |
Let me remove that plugin for now and only support with assertions. |
Try 4.1.1 |
No issues building (edit: and running) with packemon 4.1.1. While debugging 4.1.0, I tried a few things and eventually got the |
Cool. I'll close this for now and revisit in the future. |
Babel throws when an import attribute such as
import abc from "./abc.json" with { type: "json" }
orawait import("./abc.json", { assert: { type: "json" } })
is present in a source file; it suggests using @babel/plugin-syntax-import-attributes to resolve the issue.note: to enable parsing the deprecated
import abc from "./abs.json" assert { type: "json" }
syntax, the plugin'sdeprecatedAssertSyntax
option must betrue
(default: false).The text was updated successfully, but these errors were encountered: