hooks icon indicating copy to clipboard operation
hooks copied to clipboard

import clearCache Error

Open Pszz opened this issue 1 year ago • 2 comments

Uncaught Error: Module not found: Can't resolve 'ahooks/es/clearCache'

Node Version: v18.14.0

// page.tsx import { clearCache, useRequest } from 'ahooks'

// package.json "ahooks": "^3.7.8", "next": "latest", "react": "^18.2.0",

// next.config.js transpilePackages: ['ahooks'],

Pszz avatar Dec 09 '23 12:12 Pszz

The root reason is the modularizeImports config of Next.js, so in ahooks side, we can do nothing.

I have open a PR to resolve it: https://github.com/vercel/next.js/pull/54657, but this still is a temp solution, once ahooks exports a new variable that different with file name, then it will be cause this problem again.

The permanent solution is that Next.js remove ahooks from modularizeImports config, just like this PR: https://github.com/vercel/next.js/pull/58992/files, but I don't think Next.js would agree to that (maybe will), because it will hurt start performance.


similar solution: https://github.com/vercel/next.js/pull/53483


related issue/pr:

  • https://github.com/alibaba/hooks/issues/2263
  • https://github.com/vercel/next.js/pull/54657
  • https://github.com/vercel/next.js/pull/58992

liuyib avatar Dec 17 '23 11:12 liuyib

The issue may have already been resolved by: https://github.com/vercel/next.js/pull/59294/files, included in v14.0.4: https://github.com/vercel/next.js/releases/tag/v14.0.4

Is anyone able to try Next.js v14.0.4 to verify this problem? Thank you!

liuyib avatar Dec 26 '23 11:12 liuyib

https://github.com/vercel/next.js/pull/59294/files

liuyib avatar Jun 03 '24 06:06 liuyib

https://github.com/vercel/next.js/pull/59294/files

This issue has been solved in Next.js >=14.0.4

liuyib avatar Jun 03 '24 06:06 liuyib