turbopack fails to resolve subpath imports in dynamic `import()` statements with a placeholder
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/stefanprobst/issue-turbopack-subpath-imports
To Reproduce
- clone repo
- pnpm install
- pnpn build
Current vs. Expected behavior
turbopack fails to resolve subpath imports (starting with #/*, configured in package.json) in dynamic import() statements with a placeholder, e.g.:
await import(`#/messages/${locale}/index.json`);
Error:
Error: Module not found: Can't resolve ('#/messages/' <dynamic> '/index.json' | '#/messages/en/index.json')
PackageInternal requests can only be Constant strings
Note that the same works fine when using either relative paths, or typescript path aliases, e.g.:
await import(`../../messages/${locale}/index.json`);
await import(`@/messages/${locale}/index.json`);
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #28~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 15:50:57 UTC 2
Available memory (MB): 32035
Available CPU cores: 4
Binaries:
Node: 24.19.0
npm: N/A
Yarn: N/A
pnpm: 11.20.0
Relevant Packages:
next: 16.3.1-canary.21 // There is a newer canary version (16.3.1-canary.24) available, please upgrade!
eslint-config-next: N/A
react: 19.2.8
react-dom: 19.2.8
typescript: 7.0.2
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 build (local), next dev (local)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Clone the linked reproducer, install with pnpm, and run its build command to confirm the dynamic import failure. Then trace Turbopack’s handling of the package.json #/* subpath alias and compare it with the working relative and TypeScript-alias cases; done means next build and next dev resolve the JSON import without the PackageInternal constant-string error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100