-
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
Support for ESM in TypeScript projects #3385
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: b31f8c05-52a3-44ca-b22e-10ec21278d4c |
@fvictorio we use wagmi/core for some scripts which only supports ESM. Had to convert all tests to .js and extract chunks of scripts into another package for now to deal with this. |
I'm using https://github.com/sindresorhus/execa, which is ESM-only. |
Suggestion for TS ESM implementation: ts-node has a |
Copying @alcuadrado comments from monorepo:
What about
If you keep supporting two module systems, ESM modules would be able to import common.js code - which uses old sequential |
Oh, that may be a great idea actually! I think now ESM in node.js means/implies that you have top-level-await. This could work! Thanks ! |
Upvote; we are using ESM in our TypeScript project because of a dependency requirement. |
pure esm package is coming. |
I am looking to integrate Playwright with Hardhat + Wagmi in order to automate frontend testing that involves connecting to a hardhat node :) |
Upvote; we are using ESM in our TypeScript project |
do u know when? 🧐 |
upvote, many packages are ESM only now, I have to install older versions for compatibility. all my projects and code is ESM now, except for hardhat. |
Upvoting as well. We have https://github.com/lukso-network/lsp-smart-contracts In our case, this is problematic as any Hardhat Typescript project that has the The only workaround we found was in this PR by @richtera: lukso-network/lsp-smart-contracts#601. https://github.com/lukso-network/lsp-smart-contracts/pull/601/files The file in the folder looks like this: ES Lint raises a warning, but we are still able to import as shown below. import { INTERFACE_IDS } from "@lukso/lsp-smart-contracts/dist/constants.cjs.js";
const test = INTERFACE_IDS.LSP0ERC725Account; |
Following this issue. Would help a lot to get rid of some workarounds for ESM/CJS interop. |
Is there any news on the topic from the team? Should the user expect the project to be stuck on the old CJS or was any progress made with ESM? Thanks guys for the effort. |
The team is currently focused on the next version of Hardhat, which will support ESM. |
It would be great if the next version could be used with |
@kanej no news about this? do you know a good alternative to hardhat that we can use to finally have esm? |
Hardhat 3 will have support for ESM, it is currently in private Alpha. I am not aware of an ESM supporting alternative currently. |
Amazing news @kanej! Is there a possibility of joining this alpha group? |
@kanej , I would be interested to join the private alpha |
I am also interested in joining private alpha. |
@kanej i want to join private alpha as well. Completely blocked by lack of ESM support with typescript |
i managed to import esm like this: const { tsImport } = require("tsx/esm/api")
const mod = await tsImport("./my-esm-module", __filename); |
Seems that Hyperlane has an interesting approach to enable ESM with Typescript in their monorepo. Snippet of their "scripts": {
"build": "yarn version:update && yarn hardhat-esm compile && tsc && ./exportBuildArtifact.sh",
"hardhat-esm": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts",
// ...
}, |
Is there any way to get access to the alpha testing of hardhat? I've tried following the steps in this comment but I always face a few different problems, eg. problems with |
Hey @canastro, thanks for the interest. The alpha is still very rough and lacks many basic features; it is not usable for general development currently, instead being more a test bed for new capabilities. |
I found a workaround that might be specific to my use case: I have an npm package containing my smart contracts, which I need to import into other packages within my monorepo. Since the package needs to be ESM, my main goal is to export only the Typechain factories. To address this, I implemented the following steps:
I avoided creating a Hardhat task to generate a package.json in the typechains folder, as doing so would conflict with my goal of exporting the package for use in an ESM context. |
Please comment and/or upvote this issue if you need support for ESM in TypeScript projects. If possible, tell us more about your use case and why you need this and cannot just transpile to cjs.
UPDATE: We have an experimental version working
See this comment to learn how to use an experimental version of this: #3385 (comment)
The text was updated successfully, but these errors were encountered: