-
Couldn't load subscription status.
- Fork 29.7k
Description
Hello,
after upgrading our application to next.js 16 we see lots of build warnings from turbopack for a server action which handles file uploads. This only seems to happen when a certain amount of files exists and path.join() or path.resolve() is used.
Is there a way to either fix these warnings, supress them or is it simply a case of not being best practices and files should be somewhere else?
Link to the code that reproduces this issue
https://github.com/MarcJose/nextjs16-turbopack
To Reproduce
The example project reproduces this warning by creating a certain amount of dummy files in the project as postinstall and having a server action to get the path of a file at runtime.
Current vs. Expected behavior
Current:
> [email protected] build
> next build
▲ Next.js 16.0.0 (Turbopack)
Creating an optimized production build ...
Turbopack build encountered 2 warnings:
./src/actions/files.ts:32:24
The file pattern ('/ROOT/public/' <dynamic> '/' <dynamic> | '/ROOT/public' <dynamic> '/' <dynamic> | '/ROOT/public/' <dynamic> | '/ROOT/public' <dynamic>) matches 16000 files in [project]/
30 |
31 | // This also triggers the warning
> 32 | const resolvedPath = path.resolve(
| ^^^^^^^^^^^^^
> 33 | baseDir,
| ^^^^^^^^^^^^
> 34 | userPath.replace(/^\//, ""),
| ^^^^^^^^^^^^
> 35 | fileName
| ^^^^^^^^^^^^
> 36 | );
| ^^^^
37 |
38 | return resolvedPath;
39 | }
Overly broad patterns can lead to build performance issues and over bundling.
Import trace:
Server Component:
./src/actions/files.ts
./src/app/page.tsx
./src/actions/files.ts:20:22
The file pattern ('/ROOT/public/media/' <dynamic> '/' <dynamic> | '/ROOT/public/media' <dynamic> '/' <dynamic> | '/ROOT/public/media/' <dynamic> | '/ROOT/public/media' <dynamic>) matches 32000 files in [project]/
18 | // This line triggers the warning:
19 | // "The file pattern matches X files... Overly broad patterns can lead to build performance issues"
> 20 | const targetPath = path.join(mediaDir, folder, filename);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 | return targetPath;
23 | }
Overly broad patterns can lead to build performance issues and over bundling.
Import trace:
Server Component:
./src/actions/files.ts
./src/app/page.tsx
✓ Compiled successfully in 862.8ms
✓ Finished TypeScript in 650.1ms
✓ Collecting page data in 162.0ms
✓ Generating static pages (3/3) in 214.6ms
✓ Finalizing page optimization in 3.7ms
Route (app)
┌ ○ /
└ ○ /_not-found
○ (Static) prerendered as static contentExpected:
Clean build.
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sun, 19 Oct 2025 19:21:18 +0000
Available memory (MB): 61858
Available CPU cores: 16
Binaries:
Node: 22.20.0
npm: 10.9.3
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.0.0 // Latest available version is detected (16.0.0).
eslint-config-next: N/A
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Turbopack
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
No response