2 years ago

#52412

test-img

Paul Müller

Use Hardhat ES5 together with Sveltekit ES6

I'd like to use Sveltekit together with hardhat but hardhat uses commonjs require syntax, if run npx hardhat test with js ending I get the error:

Error [ERR_REQUIRE_ESM]: require() of ES Module hardhat.config.js from node_modules\hardhat\internal\core\config\config-loading.js not supported. hardhat.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.                                             Instead rename hardhat.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). 

If I change to type: commonjs I get this error if I run npm run dev:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
svelte.config.js:1
import preprocess from "svelte-preprocess";
^^^^^^

SyntaxError: Cannot use import statement outside a module

If I change svelte.config.js to svelte.config.mjs I get the follwing error: You need to create a svelte.config.js file and if I rename hardhat.config.js hardhat doesn't find the config and wants to create a new project.

Is there any way to combine these two even tho there is a mixture of import and require statements?

javascript

node.js

sveltekit

hardhat

0 Answers

Your Answer

Accepted video resources