node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

TypeError: LRU is not a constructor

Open jasmasher opened this issue 10 months ago • 6 comments

I believe there is a conflict version with the lru-cache package. After some digging noticed that lru-cache v8.0.0 is the only version that exports the class as "default" and that's how is refernced in the code

const LRU = require('lru-cache').default;

but if for some reason there is a version conflict on that library, which in my case happened you get that error. I also noticed that mysql2 has this dependeny "named-placeholders": "^1.1.3" but "named-placeholders dependecy is "lru-cache": "^7.14.1".

I'm nort sure why npm is not crying about this but in my case I'm getting lru-cache "5.1.1" which is even worst.

I fixed the issue by manually installing lru-cache v8.0.0

jasmasher avatar Apr 24 '24 14:04 jasmasher

@wellwelwel I bumped lru-cache in named-placeholders ( need to publish it, last release action failed for some reason )

Couple of notes:

  • need to revisit what stops us from using the very latest version ( 10.x now )
  • 8.0.5 exports main class as both main export as well as default export so we may no longer need to require('lru-cache').default
  • maybe remove dependency altogether from named-placeholders and require users to bring your own cache? Would be a major version bump, and we'd need to change mysql2 side to pass cache constructor ( or cache instance ).

sidorares avatar Apr 26 '24 03:04 sidorares

I bumped lru-cache in named-placeholders ( need to publish it, last release action failed for some reason )

Based on named-placeholders error:

✖ Error when creating branch
Error: release-please failed: Error creating Pull Request: Resource not accessible by integration

Possibly that's it:

Settings > Actions > General > Workflow permissions

Screenshot 2024-04-26 at 01 22 45

wellwelwel avatar Apr 26 '24 04:04 wellwelwel

need to revisit what stops us from using the very latest version ( 10.x now )

Looking at the LRU Cache breaking changes:

v9

  • Use named export only, no default export.

We could adapt the import.

v10

  • cache.fetch() return type is now Promise<V | undefined> instead of Promise<V | void>. This is an irrelevant change practically speaking, but can require changes for TypeScript users.

It just changes a type (TypeScript) from undefined to void, so it shouldn't affect MySQL2 code 🙋🏻‍♂️

wellwelwel avatar Apr 26 '24 04:04 wellwelwel

Same error for me: "LRU is not a constructor" but manually installing lru-cache at v8.0.0 did not resolve for me

npm ls lru-cache

├── [email protected]
├─┬ [email protected]
│ ├── [email protected] deduped
│ └─┬ [email protected]
│   └── [email protected]

Leigh-M avatar Jun 12 '24 10:06 Leigh-M

Same error for me: "LRU is not a constructor" but manually installing lru-cache at v8.0.0 did not resolve for me

npm ls lru-cache

├── [email protected]
├─┬ [email protected]
│ ├── [email protected] deduped
│ └─┬ [email protected]
│   └── [email protected]

I have same problem. How to solve it?

antonkushpil avatar Aug 23 '24 14:08 antonkushpil

Same error for me: "LRU is not a constructor" but manually installing lru-cache at v8.0.0 did not resolve for me

npm ls lru-cache

├── [email protected]
├─┬ [email protected]
│ ├── [email protected] deduped
│ └─┬ [email protected]
│   └── [email protected]

I have same problem. How to solve it?

I installed "lru-cache": "^11.0.0", and it fixed the issue

antonkushpil avatar Aug 23 '24 14:08 antonkushpil