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

optimizePackageImports' caches index.ts files (dev and build) when they resolve to source files outside node_modules. #65630

Open
threehams opened this issue May 10, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. SWC Related to minification/transpilation in Next.js.

Comments

@threehams
Copy link

Link to the code that reproduces this issue

https://github.com/threehams/next-optimize-caching

To Reproduce

Dev caching:

  1. Run npm run dev
  2. Add a syntax error to ui/index.ts

Build caching:

  1. Run npm run build
  2. Rename ui/Button.tsx to ui/CounterButton.tsx, and update imports in ui/index.ts
  3. Run npm run build again

Current vs. Expected behavior

Current:
Dev caching: The syntax error is not reported. The dev server caches the contents of index.ts file until server restart.

Build caching:

./ui/index.ts
Module not found: Can't resolve './Button'

The build caches the index.ts file permanently, and will fail until the .next directory is deleted.

Expected:
The Next.js 14.2 release notes encourage using optimizePackageImports: ['package-name'] to optimize barrel files. When these files are outside node_modules, the imports should be re-evaluated when those index.ts files have changed on disk, in both dev and production builds.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.10.0
  npm: 10.2.5
  Yarn: 1.22.19
  pnpm: 9.1.0
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Developer Experience, SWC

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

No response

@threehams threehams added the bug Issue was opened via the bug report template. label May 10, 2024
@github-actions github-actions bot added Developer Experience Issues related to Next.js logs, Error overlay, etc. SWC Related to minification/transpilation in Next.js. labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant