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

fix: use correct import attributes syntax #957

Conversation

kanadgupta
Copy link
Member

🚥 Resolves #950

🧰 Changes

(PR description stolen from readmeio/rdme#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:

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.

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:

process.env.NODE_ENV === 'test'
? // eslint-disable-next-line unicorn/prefer-module
`file:${path.relative(__dirname, path.dirname(require.resolve('@readme/api-core/package.json')))}`
: `^${corePkg.version}`,

but I confirmed that Node v22 works again with this change. See the before:

CleanShot 2024-11-18 at 08 32 53@2x

And the after:

CleanShot 2024-11-18 at 08 33 18@2x

@kanadgupta kanadgupta added bug Something isn't working area:api Issues related to the `api` CLI, which builds the SDKs labels Nov 18, 2024
@kanadgupta kanadgupta requested a review from erunion November 18, 2024 14:39
@kanadgupta kanadgupta marked this pull request as ready for review November 18, 2024 14:39
@kanadgupta kanadgupta merged commit 211e8fd into main Nov 18, 2024
7 checks passed
@kanadgupta kanadgupta deleted the kanad-2024-11-18/import-attributes-instead-of-import-assertions branch November 18, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues related to the `api` CLI, which builds the SDKs bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7.0.0 Unexpected identifier 'assert' with Node 22
2 participants