corbado/javascript

Corbado is not supported in recent versions of Node.js because it is not declared as an ESM module

Opened this issue · 2 comments

Describe the bug
When I was trying out the Web SDK (@corbado/web-js) it could not transpile because Corbado is not an ESM module. I receive the following error:

(node:25781) 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)
6:36:31 PM [vite] Error when evaluating SSR module /src/routes/+page.svelte: failed to import "@corbado/web-js"
|- /Users/fohlen/WebstormProjects/lesstax/node_modules/@corbado/web-js/dist/index.js:1

This is tailed by a long backtrace but boils down to using ESM.

To Reproduce
Steps to reproduce the behavior:

  1. Use Node 22, e.g 22.2.0 which is the latest via brew install node
  2. Create a Svelte project via npm create svelte@latest
  3. Install Corbado npm install --save @corbado/web-js
  4. Include it in some page import Corbado from '@corbado/web-js'
  5. Run npm run dev

Expected behavior

It should build in Node 22.

Additional context
According to StackOverflow, simply declaring the package type as:

"type": "module"

Should do the trick. Alternatively, declaring the output as .mjs will make it obvious for Node.js to pick up that it should use ESM over CommonJS.

I verified that adding "type": "module" to @corbado package configuration files is indeed a viable fix. That loads fine.

@Fohlen thanks for reporting. Unfortunately we can't just switch web-js to a ESM module. Most likely we have to support both (esm and cjs) for some time. So this requires a bit of time and I have put this request on our roadmap.