Subscribe on changes!

Cannot find module 'lru-cache/min' (something wrong from `@vue/compiler-sfc`)

avatar
Oct 31st 2023

Vue version

3.3.7

Link to minimal reproduction

link repro - 1

Steps to reproduce

open repro CleanShot 2023-11-01 at 01 29 45

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?

v3.3.4 CleanShot 2023-11-01 at 01 25 01

v3.3.5 CleanShot 2023-11-01 at 01 26 21

lru-cache@10.0.1 Install lru-cache independently is still failed because there is no lru-cache/min; CleanShot 2023-11-01 at 09 35 55@2x

I found this problem seems to be more related to tsc. link repro - 2 CleanShot 2023-11-01 at 15 30 30

Suggestion

  1. added lru-cache to dependencies https://github.com/vuejs/core/blob/9ca468c68bb1b84ce3ab5b4bedcabad3c2a7b618/packages/compiler-sfc/package.json#L50

  2. set node instead of bundler on moduleResolution property or only instead for build(tsconfig.build.json), it will work fine. https://github.com/vuejs/core/blob/9ca468c68bb1b84ce3ab5b4bedcabad3c2a7b618/tsconfig.json#L10

  3. npm run build-dts CleanShot 2023-11-01 at 15 46 07@2x

if it's not a bug, please close the issue. Because moduleResolution property set to bundler will work fine in my project.

avatar
Nov 1st 2023

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.

avatar
Nov 1st 2023

@deot thanks you I was also same issue. Your suggestions are useful.

avatar
Nov 3rd 2023

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>
}```
avatar
Nov 4th 2023

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.

avatar
Nov 5th 2023

I had the same issue in my project and I fixed by regressing vuejs to the 3.3.4 version.