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

chore(lint): switch to import attributes #25599

Closed
wants to merge 3 commits into from
Closed

Conversation

caugner
Copy link
Contributor

@caugner caugner commented Jan 7, 2025

Summary

Migrates import assertions to import attributes.

Test results and supporting details

Related issues

Part of #25596.

@github-actions github-actions bot added infra Infrastructure issues (npm, GitHub Actions, releases) of this project linter Issues or pull requests regarding the tests / linter of the JSON files. size:s [PR only] 7-24 LoC changed labels Jan 7, 2025
@caugner caugner marked this pull request as draft January 7, 2025 16:21
@caugner
Copy link
Contributor Author

caugner commented Jan 7, 2025

It looks like TypeScript or ts-node converts Import Attributes back to Import Assertions:

file:///home/runner/work/browser-compat-data/browser-compat-data/lint/linter/test-schema.ts:6
import compatDataSchema from './../../schemas/compat-data.schema.json' assert {
                                                                       ^^^^^^

SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:102:18)
    at #translate (node:internal/modules/esm/loader:437:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:484:27)

@caugner
Copy link
Contributor Author

caugner commented Jan 7, 2025

The reason for the error seems to be that we're using ts-node with SWC, and ts-node enables two experimental SWC features, keepImportAttributes and emitAssertForImportAttributes, which prevents the use of import attributes, because they're converted to import assertions.

https://github.com/TypeStrong/ts-node/blob/ddb05ef23be92a90c3ecac5a0220435c65ebbd2a/src/transpilers/swc.ts#L248-L251

@caugner

This comment was marked as outdated.

@caugner caugner closed this Jan 7, 2025
@Elchi3
Copy link
Member

Elchi3 commented Jan 7, 2025

hm, can we fix this by setting "moduleResolution" to "NodeNext" in tsconfig.json?

@caugner
Copy link
Contributor Author

caugner commented Jan 8, 2025

hm, can we fix this by setting "moduleResolution" to "NodeNext" in tsconfig.json?

No, unfortunately that doesn't make any difference. A solution would be to not use swc for the time being.

@caugner caugner reopened this Jan 8, 2025
@caugner
Copy link
Contributor Author

caugner commented Jan 8, 2025

Closing in favor of #25603.

@caugner caugner closed this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra Infrastructure issues (npm, GitHub Actions, releases) of this project linter Issues or pull requests regarding the tests / linter of the JSON files. size:s [PR only] 7-24 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants