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

allow json module imports #921

Merged
merged 1 commit into from
Aug 30, 2024
Merged

allow json module imports #921

merged 1 commit into from
Aug 30, 2024

Conversation

technophile-04
Copy link
Collaborator

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

Copy link
Member

@carletex carletex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition!

@technophile-04 technophile-04 merged commit 3b6e931 into main Aug 30, 2024
1 check passed
@technophile-04 technophile-04 deleted the allow-json-import-hardhat branch August 30, 2024 10:10
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

Successfully merging this pull request may close these issues.

2 participants