AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Fails To Resolve Subpath Imports In Dynamic Import() With Placeholder

When using Turbopack, dynamic import statements that include a template literal with a subpath import (starting with '#/') fail to resolve, throwing 'Module not found: Can't resolve ... PackageInternal requests can only be Constant strings'. Relative paths and TypeScript path aliases work correctly.

highConfidence 95%Next.jsAffected V16.3.1-Canary.21

Origin Analysis

Turbopack’s resolver treats package-internal subpath imports (#) as constant-string-only requests. Dynamic import expressions containing placeholders generate non-constant specifiers, which the resolver rejects before attempting to match the literal part of the subpath.
1. Configure package.json imports with a subpath pattern like "#/*": "./src/*". 2. In a component or module, write: await import(`#/messages/${locale}/index.json`). 3. Run `next build` or `next dev` with Turbopack enabled. 4. Observe the build error: Module not found: Can't resolve ('#/messages/' <dynamic> '/index.json' | '#/messages/en/index.json') PackageInternal requests can only be Constant strings.

Fixing Code Block

Edge Case Audit

This is a user-side workaround, not a fix for the underlying Turbopack issue. If the project structure changes, the relative path may break. After upgrading Next.js to a version that fixes the bug, revert this change and restore the original subpath imports. Test all locales and ensure the dynamic import still loads the correct module. Path aliases require proper tsconfig configuration and may need additional setup in Next.js if not already present.

Ecosystem Topology