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

[turbopack] dynamic imports fallback to single existing file when target file does not exist #74664

Open
qnten opened this issue Jan 8, 2025 · 0 comments
Labels
bug Issue was opened via the bug report template. Turbopack Related to Turbopack with Next.js.

Comments

@qnten
Copy link

qnten commented Jan 8, 2025

Link to the code that reproduces this issue

https://github.com/qnten/reproduction-dynamic-import

To Reproduce

  1. Start the application in dev with turbo enabled npm run dev
  2. The page / should display the following:
1. first file exists so "first name" should be displayed: first file
2. second file does not exist so "no name found" should be displayed: first file
3. third file does not exist so "no name found" should be displayed: first file

Current vs. Expected behavior

Current Behavior

When using dynamic import to load files from a directory that contains only one file, the import incorrectly falls back to that existing file even if the requested file does not match the import path. Specifically, in the provided example:
• First File (first.ts): Exists and correctly returns "first name".
• Second File (second.ts): Does not exist, but getExportFromFile("second") still returns "first name" instead of "no name found".
• Third File (third.ts): Does not exist, but getExportFromFile("third") also returns "first name" instead of "no name found".

This behavior occurs only when the directory contains a single file. If a second file is added (second.ts) everything works as expected.

Expected Behavior

The dynamic import should strictly attempt to load the specified file based on the provided path. If the target file does not exist within the directory, the import should throw.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.4.1
  npm: 10.8.1
  Yarn: 1.22.22
  pnpm: 9.5.0
Relevant Packages:
  next: 15.2.0-canary.1 // Latest available version is detected (15.2.0-canary.1).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

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

Turbopack

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

next dev (local)

Additional context

No response

@qnten qnten added the bug Issue was opened via the bug report template. label Jan 8, 2025
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Jan 8, 2025
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. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant