Skip to content

Use of import attributes triggers an error incorrectly #967

Closed
@wojtekmaj

Description

@wojtekmaj

Use of import attributes triggers an error in tsgo (7.0.0-dev.20250528.1), while the latest vintage 😁 TypeScript (5.8.3) does not.

tsconfig.json

{
  "compilerOptions": {
    "isolatedModules": true,
    "lib": ["es2023"],
    "module": "nodenext",
    "moduleDetection": "force",
    "noEmit": true,
    "noUncheckedIndexedAccess": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "es2022",
    "verbatimModuleSyntax": true
  }
}

Error:

src/(redacted).ts:3:49 - error TS2856: Import attributes are not allowed on statements that compile to
CommonJS 'require' calls.

3 import redacted from '../data/redacted.json' with { type: 'json' };

Out of curiosity, I changed module to node16 to see if it makes any difference. To my surprise, I got:

src/(redacted).ts:3:49 - error TS2823: Import attributes are only supported when the '--module' option
is set to 'esnext', 'nodenext', or 'preserve'.

...so it suggests me to set module to what it originally was to get rid of the error!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Module ResolutionRelated to module resolution and module checker errors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions