Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
deot opened this issue Oct 31, 2023 · 5 comments
Closed
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. regression scope: types

Comments

@deot
Copy link

deot commented Oct 31, 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

    "lru-cache": "^10.0.1",

  2. set node instead of bundler on moduleResolution property or only instead for build(tsconfig.build.json), it will work fine.

    "moduleResolution": "bundler",

  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.

@haoqunjiang
Copy link
Member

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 f5a253f#diff-7ba159198fd8831307a1c39831d6679874e024dd7e9d8ca66ce1760e3e19703dR5 This kind of type-level breaking changes should be considered a bug in Vue.

@haoqunjiang haoqunjiang added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Nov 1, 2023
@Seungwoo321
Copy link

Seungwoo321 commented Nov 1, 2023

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

@ne0guille
Copy link

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>
}```

@LiamVisionary
Copy link

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.

@dimahmz
Copy link

dimahmz commented Nov 5, 2023

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

haoqunjiang added a commit to haoqunjiang/node-lru-cache that referenced this issue Nov 6, 2023
As both `./min` and `.` points to the same type definition file,
sometimes TypeScript will resolve the type definition file to the
`./min` key as it appears first.

microsoft/TypeScript#56290 (comment)

While this is not incorrect behavior, it breaks compatibility with older
build environments that do not support the `exports` field. (e.g.
TypeScript with `moduleResolution: "node"` instead of `bundler` or
`node16`), as the `./min` entry is only available through the `exports`
field.

Some Vue.js users are experiencing this issue:
vuejs/core#9521
deot added a commit to deot/dev that referenced this issue Nov 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. regression scope: types
Projects
None yet
Development

No branches or pull requests

6 participants