-
-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: LRU is not a constructor #1885
Comments
I am also seeing this behavior with |
also related #1876 @playitcool @lamiaagabriel I tried following steps but everything worked as expected for me:
import { createConnection } from "mysql2/promise";
const DATABASE_URL='mysql://...';
export default async function handler(req, res) {
const connection = await createConnection(DATABASE_URL);
const [rows] = await connection.execute('SELECT * FROM test WHERE test.id = ?', ['119f4a6c-02f3-4f47-8103-9b5bf3b245db']);
res.status(200).json({ rows })
} |
@sidorares - thank you for looking into it. One more detail - I am also using
|
@playitcool can you make a repro repo, and also have lockfile checked in? |
Hello @sidorares, what project structure are you using? are you using the app directory? I think it may have something to do with server components. Not sure. App directory is an experimental feature and you need to explicitly enable it in next.config file. |
Can confirm I can reproduce the issue with app directory the result of this line
is not sure yet which side the fix should be - next, node-lru-cache or mysql2 There was a PR in lru-cache recently ( isaacs/node-lru-cache#266 ) adding ESM support but it's already in the version |
Is there a version we can revert back to for now? |
Downgrading to Next 13.0 made it work for me with |
I also meet this problem, and I don't know if the bug occurs from next.js or node-mysql2 |
@SpBills are you using the app directory? [edit]: just checked Next 13.0 with the App directory and the above issue still persists. |
Even in Next 13.0 app directory it didn't work. Maybe this is an app dir problem? Good point. |
Hi everyone. I also got stuck with this issue and was pulling hair of my head because I thought it should work in any node.js environment. Even in the new Next.js app router mode in page or route handler. My stack: next 13 appDir, drizzle orm with mysql, monorepo, turbo, typescript. So i started digging and experimenting and I think I found the solution. I put the So the /** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,
experimental: {
appDir: true,
typedRoutes: true,
serverComponentsExternalPackages: ["mysql2"],
// runtime: "edge",
},
}
export default config I'm not that familiar with how this works under the hood but if it works that's fine for me and I can continue playing with next 13 appDir on the edge ⚡ You can read more about this feature here: https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages EDIT: I noticed that new next.js beta docs changes frequently so if the link above doesn't work try this: https://beta.nextjs.org/docs/api-reference/next-config#servercomponentsexternalpackages |
Wow. Great catch. |
Mr wizard! Thank you! |
You are an absolute life saver! |
I have the same issue, but I work with Node.js and npm. How can this be solved for my case? |
Same issue here, Next 13.3.0 and Mysql 3.2.3. Not using app directory, but anything in /api seems to cause this error. |
@SamuelBucher can you make a repro repository? Are you using any bundler tools or its just a standard node module system? |
I rebuilt my project for Next.js, but this solution still didn't work. |
@SamuelBucher Could you share a repro link? It's difficult to help without it. Next.js in app dir mode is being updated daily by dev team through releases (canary) and maybe some new issue appeared. |
I've already solved this issue by messing with versions in package.json "dependencies": { |
Perfect! Issue fixed! God bless 🙏🏼 |
Nuxt3 #2001 (comment) |
Build for electron,it's the same problem . |
Hi @Tenodec, can you share a basic repro? Also, knowing the electron and mysql2 versions might help 🙋🏻♂️ |
Githubにissueが上がっていました、その通りに対処して解決しました sidorares/node-mysql2#1885
you really a life saver 🙏 |
This error appears each time I install mysql2 using (yarn add mysql2 --save) with Next.js 13.2.
I reinstalled Next.js and mysql2 without any other dependencies to ensure it wasn't another dependency that affects it.
(
Server Error
TypeError: LRU is not a constructor
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
eval
node_modules\mysql2\lib\parsers\parser_cache.js (5:20)
(sc_server)/./node_modules/mysql2/lib/parsers/parser_cache.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (1470:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
require
node_modules\mysql2\lib\parsers\text_parser.js (7:20)
(sc_server)/./node_modules/mysql2/lib/parsers/text_parser.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (1492:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
require
node_modules\mysql2\lib\commands\query.js (10:22)
(sc_server)/./node_modules/mysql2/lib/commands/query.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (986:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
require
node_modules\mysql2\lib\commands\index.js (5:14)
(sc_server)/./node_modules/mysql2/lib/commands/index.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (953:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
require
node_modules\mysql2\lib\connection.js (29:17)
(sc_server)/./node_modules/mysql2/lib/connection.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (1041:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
require
node_modules\mysql2\index.js (5:19)
(sc_server)/./node_modules/mysql2/index.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (799:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
require
node_modules\mysql2\promise.js (3:13)
(sc_server)/./node_modules/mysql2/promise.js
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (1558:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
eval
webpack-internal:///(sc_server)/./utils/db.ts (5:72)
(sc_server)/./utils/db.ts
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (1920:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
eval
webpack-internal:///(sc_server)/./app/api/employees/route.ts (8:67)
(sc_server)/./app/api/employees/route.ts
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (216:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
eval
webpack-internal:///(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js (13:106)
(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Femployees%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Femployees%2Froute.ts&appDir=D%3A%5CWebsites%5Cnext-mysql%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=D%3A%5CWebsites%5Cnext-mysql&isDev=true&tsconfigPath=tsconfig.json&assetPrefix=!
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (205:1)
webpack_require
file:///D:/Websites/next-mysql/.next/server/webpack-runtime.js (33:42)
webpack_exec
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (2073:39)
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (2074:28)
Object.
file:///D:/Websites/next-mysql/.next/server/app/api/employees/route.js (2077:3)
Module._compile
node:internal/modules/cjs/loader (1254:14)
Module._extensions..js
node:internal/modules/cjs/loader (1308:10)
Module.load
node:internal/modules/cjs/loader (1117:32)
Module._load
node:internal/modules/cjs/loader (958:12)
Module.require
node:internal/modules/cjs/loader (1141:19)
require
node:internal/modules/cjs/helpers (110:18)
Object.requirePage
file:///D:/Websites/next-mysql/node_modules/next/dist/server/require.js (88:12)
file:///D:/Websites/next-mysql/node_modules/next/dist/server/load-components.js (49:73)
process.processTicksAndRejections
node:internal/process/task_queues (95:5)
async Object.loadComponentsImpl [as loadComponents]
file:///D:/Websites/next-mysql/node_modules/next/dist/server/load-components.js (49:26)
async DevServer.findPageComponentsImpl
file:///D:/Websites/next-mysql/node_modules/next/dist/server/next-server.js (599:36)
)
The text was updated successfully, but these errors were encountered: