-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cannot read properties of undefined (reading 'Client') error in Next.js when .mjs
files are configured to be handled by Webpack
#54
Comments
Thanks for this report, I'll take a look soon. |
OK, I can reproduce both the problem ( I'm not a Next.js/Webpack/module resolution expert, but I can't immediately identify anything wrong in the way we export CJS and ESM. Since things now work fine out-of-the-box, and fail when using the custom-config workaround, I'm not sure that the bug is on our side. I agree, of course, that it would be nice if it would just work, wherever the bug is ... |
@amitdahan Thanks very much for establishing that the problem here was down to the scourge of default imports! @joulev I think version 0.7.0, just released and based on 45e34e1, should fix this issue. Please do let us know either way. |
I can confirm v0.7.0 works perfectly! Thanks so much to both of you! |
Steps to reproduce
Clone https://github.com/joulev/debug/tree/drizzle-orm-fail-webpack-config
Add an
.env
file at the same level withpackage.json
withDATABASE_URL
being the connection string of any Neon databases. Empty databases work too, no migrations or schema pushes necessary.pnpm install
, thenpnpm build
You will see the error
If you remove the following lines from
next.config.js
and rebuild again, it will function normally and get an error like
relation "a_table_that_does_not_exist" does not exist
(expected error).Expected result
Even with the Webpack config lines added, it should still work (which means it will throw that the table doesn't exist, and if the table actually exists it will query and return the data normally).
Actual result
It gets the
TypeError
above.Environment
@neondatabase/serverless
v0.6.0macOS 14.1.2 (Sonoma),
node
v20.3.1,pnpm
v8.11.0Logs, links
Correct error message
Buggy error message
Additional contexts
It's very likely the issue reported by @/feliche93 here using the serverless/websocket driver fails locally? #26 (comment).
Until Next.js v14.0.4-canary.33, this Webpack config was necessary for Next.js to handle ESM files well, ref: ESM in .mjs files cause a dev mode runtime error vercel/next.js#17806 (comment). Now, although Next.js has patched this, the patch is still very new (a few days old) and in the ecosystem many packages/plugins have baked this workaround config to their source code and haven't updated them. Hence for a while more, this config is likely to be added (directly by the developer, or indirectly by third-party plugins) to many codebases.
Still, even when Next.js has patched this, I think it's still a bug on
@neondatabase/serverless
's side because things, well, shouldn't break simply because the user opts to handle.mjs
files as well.The text was updated successfully, but these errors were encountered: