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

Are import attributes supported? #27

Open
bennycode opened this issue Aug 29, 2024 · 1 comment
Open

Are import attributes supported? #27

bennycode opened this issue Aug 29, 2024 · 1 comment

Comments

@bennycode
Copy link
Contributor

TypeScript 5.3 supports import attributes, but when I execute the following code, I don't see anything on my terminal:

import diags from '../examples/dump-1724954858848.json' with {type: 'json'};

console.log(diags.length);
console.log(diags.map(diag => diag.code).join(', '));
TSIMP_DIAG=error node --import=tsimp/import ./src/main.ts

When I use ts-node instead, printing works fine:

node --no-warnings=ExperimentalWarning --loader ts-node/esm ./src/main.ts
@mdmower-csnw
Copy link

mdmower-csnw commented Sep 4, 2024

@bennycode - it seems to work ok for me.

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022"],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "resolveJsonModule": true,
    "strict": true
  }
}

package.json

{
  "type": "module",
  "devDependencies": {
    "@types/node": "^20.16.4",
    "tsimp": "^2.0.11"
  }
}

my.json

{ "msg": "hello world" }

index.ts

import myjson from './my.json' with {type: 'json'};
console.log(myjson.msg);

Run it

> node --import=tsimp/import .\index.ts
hello world
(node:8044) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

I did run into some cache issues (probably related to #20), but this got things working again:

> npx tsimp --clear
tsimp: daemon stopped
tsimp: cache cleared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants