"[ERROR] require() of ES Module node_modules/.pnpm/nanoid@5.0.4/node_modules/nanoid/index.js from node_modules/.pnpm/elysia@0.8.10_@sinclair+typebox@0.32.12_typescript@5.3.3/node_modules/elysia/dist/cjs/ws/index.js not supported. Instead change the require of node_modules/.pnpm/nanoid@5.0.4/node_modules/nanoid/index.js in node_modules/.pnpm/elysia@0.8.10_@sinclair+typebox@0.32.12_typescript@5.3.3/node_modules/elysia/dist/cjs/ws/index.js to a dynamic import() which is available in all CommonJS modules." when integrating with Astro #441
Labels
bug
Something isn't working
What version of Elysia.JS is running?
0.8.10
What platform is your computer?
Darwin 23.2.0 arm64 arm
What steps can reproduce the bug?
I follow the docs here: https://elysiajs.com/integrations/astro.html
Steps as follows:
create-astro
pnpm add elysia @sinclair/typebox
Note
The docs used
export const GET = handle; export const POST = handle
but now Astro supports theALL
method. Maybe the docs can be updated to use more idiomatic pattern?pnpm dev
to start astro dev server.What is the expected behavior?
The app should work. Navigating to http://localhost:4321/services/hello should work.
What do you see instead?
When trying to access the endpoint, this error is generated instead:
Additional information
It seems that Elysia is compiled into CommonJS and is always preferred in Node.js
Note the order of conditional exports.
node
comes beforeimport
. This means that the CJS version of Elysia will be imported in Node.js regardless of whether Elysia.js is required or imported.However, the CJS version of Elysia.js is currently broken, as the
ws
module tries to require thenanoid
package, which is ESM-only.Note these 2 points in the docs:
I currently work around this issue by patching
node_modules/elysia/dist/cjs/index.js
to comment out the line that importsws
.This made the app work for now, but not ideal to have to patch a dependency like this.
Maybe Elysia should have an integration test suite that ensures it works with Astro? (As well as other environments like Cloudflare Workers? (It was broken in earlier version.))
The text was updated successfully, but these errors were encountered: