hardhat
hardhat copied to clipboard
Error HH19: Your project is an ESM project (you have "type": "module" set in your package.json) but your Hardhat config file uses the .js extension.
Version of Hardhat
2.19.4
What happened?
In trying to move my project to ESM, node20, vite, and other upgrades, I am completely stuck on run hardhat. It gives me a confounding error that the config file ends in .js, when it clearly ends in .ts. I've tried a lot of debugging and can't get anywhere.
Here is my error:
❯ HARDHAT_VERBOSE=true npx hardhat
hardhat:core:vars:varsManager Creating a new instance of VarsManager +0ms
hardhat:core:vars:varsManager Loading ENV variables if any +0ms
hardhat:core:config Loading Hardhat config from /Users/x/dev/yz/hardhat/hardhat.config.ts +0ms
Error HH19: Your project is an ESM project (you have "type": "module" set in your package.json) but your Hardhat config file uses the .js extension.
Rename the file to use the .cjs to fix this problem.
For more info go to https://hardhat.org/HH19 or run Hardhat with --show-stack-traces
I don't have a hardhat.config.js anywhere. If I do a build, one shows up in the ./dist dir but I can delete that and get same error.
Here is my tsconfig.json:
{
"compilerOptions": {
"declaration": true,
"target": "ESNext",
"module": "esnext",
"allowJs": true,
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "dist",
"skipLibCheck": true,
"rootDirs": ["./scripts"],
"isolatedModules": true,
"lib": ["esnext"]
},
"include": ["./typechain", "./deploymentInfo.json","hardhat.config.ts"],
"exclude": ["node_modules", "dist"],
}
Minimal reproduction steps
I don't have a great reproduction mechanism yet, but can try to provide one if there are no ideas here.
Search terms
No response
After submitting I see that TS isn't supported. I'm using TS+Node20. I tried the workaround that came out Dec 5 and it didn't work, here: https://github.com/NomicFoundation/hardhat/issues/3385#issuecomment-1891392542
@CryptoGraffe I don't think we can help without some way to reproduce the issue. Can you share a link to your repo if it's public?
@fvictorio
git clone [email protected]:coordinape/coordinape.git
cd coordinape
git checkout vite
nvm use 20
git submodule init
cd hardhat
pnpm install
HARDHAT_VERBOSE=true npx hardhat
...
Done in 7.2s
hardhat:core:vars:varsManager Creating a new instance of VarsManager +0ms
hardhat:core:vars:varsManager Loading ENV variables if any +1ms
hardhat:core:config Loading Hardhat config from /Users/x/tmp/coordinape/hardhat/hardhat.config.ts +0ms
Error HH19: Your project is an ESM project (you have "type": "module" set in your package.json) but your Hardhat config file uses the .js extension.
Rename the file to use the .cjs to fix this problem.
For more info go to https://hardhat.org/HH19 or run Hardhat with --show-stack-traces
I am also having the same issue .... any luck ?
@dipanshuhappy I've removed the import of .js module from my hardhat.config.cts
and the error is gone.
@dipanshuhappy I've removed the import of .js module from my
hardhat.config.cts
and the error is gone.
Got it thanks , this issue can be closed then ?
Getting the same error when trying to use https://github.com/Destiner/abi-coder
@mktcode can you open a separate issue with steps to reproduce it?
EDIT. I think our issue was caused by a dependency override with PNPM. Not sure if this comment is relevant anymore.
Reporting the same error, in my case it only happens when trying to import the @nomicfoundation/hardhat-toolbox 3.0.0 in the project.
Attaching PR for reference: https://github.com/FuelLabs/fuel-bridge/blob/ad7b34ae90ff7fdcdb812403f6d798f8ed94051e/packages/solidity-contracts/hardhat.config.ts#L3
I guess we will be avoiding the toolbox for the time being
To reproduce:
-
pnpm install
at the root of the repository - Uncomment the line importing hardhat-toolbox at
packages/solidity-contracts/hardhat.config.ts
-
cd packages/solidity-contracts && pnpm compile
Posting a summary and reproduction steps for clarity. While others reported similar issues with fixes, the original issue is valid:
Version of Hardhat
2.19.4
What happened?
After migrating to ESM, running Hardhat fails with the error "Error HH19: Your project is an ESM project (you have 'type': 'module' in your package.json) but your Hardhat config file uses the .js extension," but the Hardhat config has the .ts extension.
Minimal reproduction steps
git clone [email protected]:coordinape/coordinape.git
cd coordinape
git checkout vite
nvm use 20
git submodule init
cd hardhat
pnpm install
HARDHAT_VERBOSE=true npx hardhat
Same here - upgraded all dependencies and a working typescript project stopped working.
I was able to update a couple of Hardhat projects' dependencies to the latest versions by excluding chai. For example, Solidstate uses the latest versions of all nomicfoundation packages, but requires chai 4.x. Although the error messages suggests that this is a Hardhat issue, I don't think that it is.
Yep, I've downgraded chai to 4.3.7 and everything works now
hi @ItsNickBarry @lukastanisic99, thanks for the update. Chai 5 only supports ESM, and it's not compatible with the hardhat v2 ESM workaround, as the hardhat config is still CommonJS. OP issue is still valid, as it is using chai 4.x.
I research about this issue. The solution that worked for me was to remove this line in the hardhat config file: 'import "@nomicfoundation/hardhat-toolbox";'
Having the same issue here.
I've tried to migrate my newly-created typescript hardhat project to ESM, but switch back to CJS cuz there are some issues can't be solved with ease.
At first, I encountered Unknown file extension ".ts"
and solve by using tsx suggested here
But hardhat use ts-node internally, according to Hardhat Document
At the moment, it's not possible to use ESM in TypeScript projects.
Hardhat uses ts-node to run TypeScript projects, which in turn relies on Node's loader hooks. This is all experimental and the current functionality is not enough for Hardhat's needs.
So basically almost all commands (eg. `npx hardhat run') use ts-node indeed.
And for the requirement of using hardhat cli, I have to switch back to ts-node, and there're issues cannot be easily solved by just using ts-node and this and that... emmm that's in a dilemma :S
I research about this issue. The solution that worked for me was to remove this line in the hardhat config file: 'import "@nomicfoundation/hardhat-toolbox";'
That fixed it for me too, but the toolbox is required for running tests. Looks like ignition deploy is also broken and returns
pnpm exec hardhat ignition deploy ./ignition/modules/Animal.ts --network localhost
Error HH303: Unrecognized task 'ignition'
For more info go to https://hardhat.org/HH303 or run Hardhat with --show-stack-traces
Yep, I've downgraded chai to 4.3.7 and everything works now
Stuck on the same thing, this worked for me!!!
removing node_modules
and using npm i
instead of pnpm i
also works.
All of my previously working hardhat projects have become impossible to re-configure lately...