scaffold-eth / scaffold-eth-2

Open source forkable Ethereum dev stack
https://scaffoldeth.io
MIT License
1.42k stars 894 forks source link

allow json module imports #921

Closed technophile-04 closed 2 months ago

technophile-04 commented 2 months ago

Description

This allows importing json in .ts files for example in scripts.

to test :

cd packages/hardhat
echo '{"test": "value"}' > scripts/test.json

then create a new file in scripts/test.ts and try importing it:

import test from "./test.json";
console.log(test);

^ on main branch above should give you ts error:

"Cannot find module './test.json'. Consider using '--resolveJsonModule' to import module with '.json' extension. [2732]"

But on this branch it should work.

Also to see if script runs at runtime properly make sure you are cd packages/hardhat and then run :

yarn hardhat run scripts/test.ts