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

Hardhat compile - "Cannot use import statement outside a module" / tsconfig.json esnext #1808

Closed
martinoss opened this issue Aug 18, 2021 · 4 comments

Comments

@martinoss
Copy link

I wanted to create a combined project with Hardhat and a React frontend, both configured to use typescript.

My plan was to share the same tsconfig.json, but Hardhat forces me to use "module": "commonjs" and React automatically changes the setting back to "esnext" when starting the application.

When I run "npx hardhat compile" for example, I get the error "Cannot use import statement outside a module"

The exception is thrown here, caused by require():

https://github.com/nomiclabs/hardhat/blob/ee4969a0a8f746f4775d4018326056d161066869/packages/hardhat-core/src/internal/core/config/config-loading.ts#L23

Is it required to configure commonjs when working with hardhat?

@alcuadrado
Copy link
Member

Hey @martinoss,

Sorry for the late answer. Unfortunately, Hardhat doesn't support ESM yet.

We'll make an announcement once once we support it.

@sedhuait
Copy link

sedhuait commented Oct 12, 2021

@martinoss : Could you help me with the workaround? Did you use multiple tsconfig?

@alcuadrado : Do you have any ETA?

@fvictorio
Copy link
Member

Do you have any ETA?

We don't. And to be honest, I don't think we'll work on this anytime soon. We do want to support it at some point, but it's not on our short or mid-term roadmap right now.

potomak added a commit to curlybracketshq/stunning-potato that referenced this issue Feb 11, 2022
Hardhat and react projects can't easily coexist.

NomicFoundation/hardhat#1808
@Sceat
Copy link

Sceat commented Sep 26, 2022

for anyone finding this issue, know that it has been partly fixed in #957 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants