Closed TroyCoombs closed 1 year ago
Can you run npm ls lru-cache
to verify?
And if it is 9.1.1, run npm why lru-cache
to verify that nothing else is getting the wrong version.
npm ls lru-cache
gives this,
├─┬ @google-cloud/datastore@6.6.2
│ └─┬ google-gax@2.30.1
│ └─┬ google-auth-library@7.14.0
│ └── lru-cache@6.0.0
├─┬ @google-cloud/pubsub@3.0.1
│ └─┬ google-auth-library@8.0.2
│ └── lru-cache@6.0.0
├─┬ @google-cloud/storage@5.19.1
│ └─┬ google-auth-library@7.14.1
│ └── lru-cache@6.0.0
├─┬ @typescript-eslint/eslint-plugin@5.16.0
│ └─┬ semver@7.3.8
│ └── lru-cache@6.0.0
├─┬ google-auth-library@6.1.6
│ └── lru-cache@6.0.0
└── lru-cache@9.1.1
If you open up node_modules/lru-cache/dist/cjs/index.js
in an editor, do you see class LRUCache {
on line 139, and exports.LRUCache = LRUCache;
on line 1394?
If you open up node_modules/lru-cache/dist/mjs/index.js
in an editor, do you see export class LRUCache {
on line 136?
Also, if you add console.log(require.resolve('lru-cache'))
to your program, what does it output?
Regarding this,
If you open up
node_modules/lru-cache/dist/cjs/index.js
in an editor, do you seeclass LRUCache {
on line 139, andexports.LRUCache = LRUCache;
on line 1394?If you open up
node_modules/lru-cache/dist/mjs/index.js
in an editor, do you seeexport class LRUCache {
on line 136?
the answer us yes to all of it.
And regarding this,
Also, if you add
console.log(require.resolve('lru-cache'))
to your program, what does it output?
I get /core/server/node_modules/lru-cache/index.js
Ok. Then the lru-cache that your program is loading is definitely not v9.1.1.
I'm not sure how you're building the deps for your server, but what it's getting is an old version.
I'm got hit with the same issue when migrating from webpack to vite with interop set to true
While debugging raw JS it seems that it's loading the proper version and it's properly initialized when for my own code.
Error seems to happen with SemVer dependency not loading an older version for it's range function
range = Range2; const LRU = LRUCache; const cache2 = new LRU({ max: 1e3 });
compared to my code
this.cache = new LRUCache.LRUCache(cacheOptions);
If your package manager or rollup builder isn't providing libraries with dependencies in their stated version ranges, there's not much I can do about that as the library author. Sounds like a vite bug.
I got a similar error, "LRUCache is not a constructor". The weird thing in my case was that it was working fine on my Mac, but not my Windows dev machine (mine's a Tauri app running everything in a webview so I'm building on both). I'm using Vite as well.
The comment that it might be picking the wrong version gave me the feeling that maybe it's some weird module resolution issue, so I blew everything away with rm -rf node_modules
and re-ran yarn
and the error went away! Pretty unsatisfying fix, but worth a shot anyway.
Hello,
Error is in this line: https://github.com/npm/node-semver/blob/ec49cdcece9db0020d6829b246681ff65a393644/classes/range.js#L201
It has been introduced in semver 7.3.3.
Solution is to downgrade to 7.3.2 or fix in node-semver :)
In order to downgrade add below to your package.json:
NPM:
{
"overrides": {
"semver": "7.3.2"
}
}
Yarn:
"resolutions": {
"semver": "7.3.2"
}
Hope it helps.
Just reiterating again:
This is not a lru-cache error. This is a package manager error. Please stop reporting it here. I cannot fix yarn.
Get this error
TypeError: lru_cache_1.LRUCache is not a constructor
when calling the constructor.Running version 9.1.1