Cannot find module 'lru-cache/min' (something wrong from `@vue/compiler-sfc`)
Vue version
3.3.7
Link to minimal reproduction
Steps to reproduce
open repro
What is expected?
no error
What is actually happening?
error
node_modules/.pnpm/@vue+compiler-sfc@3.3.7/node_modules/@vue/compiler-sfc/dist/compiler-sfc.d.ts:1:32 - error TS2307: Cannot find module 'lru-cache/min' or its corresponding type declarations.
1 import * as lru_cache_min from 'lru-cache/min'
Found 1 error in node_modules/.pnpm/@vue+compiler-sfc@3.3.7/node_modules/@vue/compiler-sfc/dist/compiler-sfc.d.ts:1
Any additional comments?
lru-cache@10.0.1
Install lru-cache
independently is still failed because there is no lru-cache/min
;
I found this problem seems to be more related to tsc
. link repro - 2
Suggestion
added
lru-cache
to dependencies https://github.com/vuejs/core/blob/9ca468c68bb1b84ce3ab5b4bedcabad3c2a7b618/packages/compiler-sfc/package.json#L50set
node
instead ofbundler
onmoduleResolution
property or only instead for build(tsconfig.build.json
), it will work fine. https://github.com/vuejs/core/blob/9ca468c68bb1b84ce3ab5b4bedcabad3c2a7b618/tsconfig.json#L10npm run build-dts
if it's not a bug, please close the issue. Because moduleResolution
property set to bundler
will work fine in my project.
The rewriting of lru-cache
to lru-cache/min
looks like a TypeScript bug to me.
On the other hand, we accidentally exposed the lru-cache
type to the end user in https://github.com/vuejs/core/commit/f5a253f69f9a2d6a141839675d0e32f145471afd#diff-7ba159198fd8831307a1c39831d6679874e024dd7e9d8ca66ce1760e3e19703dR5 This kind of type-level breaking changes should be considered a bug in Vue.
would be ok to revert it back to ?
export function createCache<T extends {}>(
max = 500
): Map<string, T> & { max?: number } {
if (__GLOBAL__ || __ESM_BROWSER__) {
return new Map<string, T>()
}
return new LRUCache({ max }) as any as Map<string, T>
}```
Was also experiencing the same issue today. I worked around it by changing lru-cache/min to lru-cache in compiler-sfc.d.ts. This fixed building on my side, but the issue still existed when Render (my web-hosting platform of choice) installed all packages and tried to build the project. Fixed it by creating a post-install script to patch the compiler-sfc. I then modified package.json to include it under scripts: "postinstall": "node ./scripts/fix-lru-cache-import.js"
Here's the script for anyone looking for a temporary solution: https://codefile.io/f/YITb201MO5
This definitely seems like a bug though.