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.jsServer ActionsRoute HandlersAffected 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

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state