TC39 updated their import assertions to be import attributes and it's a bit of a mess now that we're running tests against Node v22.
Here's what importing JSON in ESM used to look like:
import { x } from "./mod" assert { type: "json" }
now it looks like this:
import { x } from "./mod" with { type: "json" };
Support for this new with keyword was added in Node v18.20.0 and Node v20.10.0 (and is supported on all v21 and v22 channels), but importantly the older assert keyword is not supported in Node v22, so unfortunately our package.json#engines.node field is going to look a little ridiculous for the time being.
🧰 Changes
(PR description stolen from https://github.com/readmeio/rdme/pull/993)
TC39 updated their import assertions to be import attributes and it's a bit of a mess now that we're running tests against Node v22.
Here's what importing JSON in ESM used to look like:
now it looks like this:
Support for this new
with
keyword was added in Node v18.20.0 and Node v20.10.0 (and is supported on all v21 and v22 channels), but importantly the olderassert
keyword is not supported in Node v22, so unfortunately ourpackage.json#engines.node
field is going to look a little ridiculous for the time being.Details: https://github.com/tc39/proposal-import-attributes?tab=readme-ov-file#history
🧬 QA & Testing
Annoyingly, we don't have anything in our unit tests to catch this sort of thing at the moment because we have stuff like this:
https://github.com/readmeio/api/blob/353cd8b52cdab893f7297f0fbf3ced1da6de352c/packages/api/src/codegen/languages/typescript/index.ts#L127-L130
but I confirmed that Node v22 works again with this change. See the before:
And the after: