Open bennycode opened 2 weeks ago
@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
TypeScript 5.3 supports import attributes, but when I execute the following code, I don't see anything on my terminal:
When I use
ts-node
instead, printing works fine: