hooks
hooks copied to clipboard
import clearCache Error
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'],
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
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!
https://github.com/vercel/next.js/pull/59294/files
https://github.com/vercel/next.js/pull/59294/files
This issue has been solved in Next.js >=14.0.4