-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Initial support for ES Modules #3043
Comments
This issue is also being tracked on Linear. We use Linear to manage our development process, but we keep the conversations on Github. LINEAR-ID: 6e5e4298-5f0d-4e67-8e6f-1002ab3a321a |
Personally, I think this reason is not enough to disable TypeScript support. |
It's not that we are disabling it, it's that we don't want to invest significant time adding support for it right now if the result might break anytime soon. But we might re-consider this in some months. If this is something you want or need, please upvote this issue |
this is actually quite a significant limitation because any of the hardhat plugins which depend on ESM-only modules (ex. IPFS https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/package.json#L21 ) will have to be held back to older versions, which has been starting to lead to problems at least with the plugin that I am working on. Any plans to change this in the near future? |
@Olyno the problem here is this: you want to write your Hardhat project in TS, and you want to transpile to ES modules (because one of your dependencies is ESM only). To execute your scripts/tests without having to compile the project, you have to use something like How does bundling Hardhat itself fixes that?
@dbeal-eth Yeah, definitely. We are just starting with ESM support for js projects because it's easier and we can support it without any major trade-offs. That doesn't mean we don't want to add ESM support for ts projects. We might just end up doing the |
@fvictorio actually my earlier query was regarding the restriction where the |
Oh, I see. Yeah, that will be a major breaking change, so it will have to wait until a future v3 of Hardhat. |
I'm using hardhat in a sveltekit project with a
And this installs automatically hardhat: "0.1.0" (which does not seem to be the esm version??) instead of the "2.12.0-esm.1" that should be installed from the `dependencies":
the only solution I found for now is to add an |
Hey @mime29, can you open a separate issue and describe your system in detail? Thanks |
I don't claim to understand many (any?) details surrounding ESM, hardhat and node; and I'm not sure that this issue is the best place to report this, but it's where I arrived after googling about I wanted to report that setting "module," to node16 or nodenext instead of commonjs, allows a hardhat.config.ts file that uses import statements to run...
|
ESModules are mandatory in Next.js TS projects, so importing the Hardhat Runtime is impossible in Typescript Next.js projects. |
Hardhat can't be used in the browser. Or do you mean a combined node+next.js project? |
@alcuadrado I don't expect it to run in the browser. I opened a new issue with more details here: #3676 |
Released in Hardhat v2.13.0 🎉 |
We are working on adding some support for using ES Modules in Hardhat projects. We can't provide full support yet because Hardhat's plugin system relies on plugins being loaded synchronously, in the CommonJS model, and ESM works in a different way.
We'll only support ESM in javascript projects, because we rely on
ts-node
for typescript projects and their support for ESM is not quite ready. For example, they rely on an experimental API of Node that is not stable and triggers some annoying warnings.Hardhat projects that use ESM will need to have a
hardhat.config.cjs
file (a CommonJS config file) and all the files required by it will need to be CJS too. But the rest of the project, including scripts and tests, will be writable in ESM.You can try this right now by installing the
esm
tag of Hardhat:If you find any problems, please leave a comment here or open an issue about it. Any feedback on this, whether if it's working or not, is super appreciated.
Todo:
.cjs
/.mjs
files when running thetest
task.cjs
hardhat config during initialization if the projects hastype: module
The text was updated successfully, but these errors were encountered: