Fixes issue in Node 22 of Hanko not being a valid module
Description
In Node 22 the following error is generated when installing Hanko Elements:
(node:30657) 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)
You can try this out by:
using Node 22 (e.g brew install node@22)
using SvelteKit (e.g npm create svelte@latest mytest)
This is caused by the fact that HankoElements is not declared as an ESM module correctly. As Node.js is migrating away from CommonJS, this is a rather known bug in many packages. To fix this issue, you have two options:
declare the module type
use .mjs which will instruct Node.js to import files using ESM
Fixes issue in Node 22 of Hanko not being a valid module
Description
In Node 22 the following error is generated when installing Hanko Elements:
You can try this out by:
brew install node@22
)npm create svelte@latest mytest
)npm install --save @teamhanko/hanko-elements
)npm run dev
)This is caused by the fact that HankoElements is not declared as an ESM module correctly. As Node.js is migrating away from CommonJS, this is a rather known bug in many packages. To fix this issue, you have two options:
.mjs
which will instruct Node.js to import files using ESMThe later however isn't really supported by browsers.
Tests
Updating the
package.json
of an installed Hanko Elements with the proposed diff "just works" and unbreaks builds.Additional context
I attached a vite_build.log log for reference.