Error message when using LRU store driver
Hi, following on my previous post about 1h ago, I decided to give the LRU storage driver a try. It worked just fine on one website, but gave me this error on another one:
TypeError: Class constructor LRUCache cannot be invoked without 'new'
Both sites are almost identical. Some dependencies might not be the exact same version though.
All I did was setting this in nuxt.config.ts:

9 Replies
Hi @CedsTrash. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I notice you're trying to use the LRU cache driver in Nuxt, but you didn't include the error message you're experiencing. Based on the knowledge sources, I can provide some information about using the LRU cache driver with Nuxt.
The LRU cache driver is part of the unstorage package that Nuxt uses for storage. It keeps cached data in memory using the LRU (Least Recently Used) Cache algorithm. By default, it's configured to store a maximum of 1000 items, but you're trying to set it to 200 in your configuration.
Without seeing the specific error message, it's difficult to pinpoint the exact issue. However, here are some potential causes:
1. Version compatibility issues: As you mentioned, the sites might have different dependency versions. This could be causing conflicts, especially if there are differences in the unstorage, nitro, or h3 package versions.
2. Configuration format: Make sure your configuration format is correct for the version of Nuxt you're using.
3. Driver availability: Ensure the LRU cache driver is properly installed and available.
If you're experiencing issues with caching in Nuxt, you might want to check out the unstorage documentation on LRU cache for more details on the available options and proper configuration.
To better help you, I'd need to see the specific error message you're encountering. Also, checking the versions of your dependencies (particularly nuxt, nitropack, and h3) might help identify version-specific issues.
I hope this helps! Let me know if you can provide more details about the error.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1014896388758323331> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai Can you re-evaluate your answer now that I included the error message?
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize, but I don't see any error message included in your follow-up question. You mentioned in your original question that you encountered an error when using the LRU store driver, but you didn't actually include the error text or screenshot.
Without seeing the specific error message, I can only provide general guidance about LRU cache issues in Nuxt. If you could share the exact error message you're encountering, I would be able to provide a more targeted analysis and solution.
Some common issues with storage drivers in Nuxt might include:
1. Version incompatibilities between dependencies (as you mentioned the sites have different dependency versions)
2. Configuration syntax errors
3. Memory limitations
4. Conflicts with other caching mechanisms
If you can share the specific error message, I'd be happy to re-evaluate and provide a more helpful answer based on the knowledge sources available.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1014896388758323331> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai Here is the error message:
TypeError: Class constructor LRUCache cannot be invoked without 'new'
Let me check the knowledge base for you again. One moment! :books:
----------------------
Thank you for providing the error message. This specific error -
TypeError: Class constructor LRUCache cannot be invoked without 'new'
- is related to how the LRU cache is being instantiated.
Based on the knowledge sources, this appears to be a compatibility issue between different versions of dependencies in your Nuxt project. Recent issues in the Nuxt GitHub repository suggest there might be problems with dependency resolution, particularly with packages like ohash, nitro, and h3.
Several users have reported similar issues in recent GitHub discussions. For example, in issue #31222, a user mentioned encountering errors related to Nitro, h3, and ohash methods, which they resolved by pinning specific versions of dependencies.
The error you're seeing indicates that the code is trying to use the LRUCache constructor without the new
keyword, which is a JavaScript syntax requirement for class constructors.
Here's a potential solution based on what worked for others:
Try adding overrides in your package.json to pin specific versions of dependencies:
Alternatively, you could try:
1. Clearing your node_modules and reinstalling dependencies
2. Using a different storage driver temporarily (like the memory driver)
3. Updating to a specific version of Nuxt that's known to work with the LRU cache driver
This issue appears to be related to how dependencies are being resolved and hoisted in your project, rather than a problem with your configuration itself.
If you continue to experience issues, checking the exact versions of all related packages (nuxt, nitropack, h3, ohash) might help identify the specific conflict.
I hope this helps resolve your issue!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1014896388758323331> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I brought over the package-lock.json file from the working project, deleted the node_modules folder, ran
npm install
, and it now works. Pretty hard to pinpoint which dependency was actually causing the issue.