Subpath imports for external modules are not supported as per Node.js specifications.
The issue involves subpath imports not supporting external modules as specified by Node.js documentation. The problem occurs during development and build stages, affecting module resolution. The fix likely requires changes in how Next.js handles module resolution, particularly for external packages.
https://github.com/ysulyma/nextjs-subpath-imports-external-bug
Module not found: Can't resolve '#image'Node.js docs specify that imports field is allowed to map to external packages: https://nodejs.org/api/packages.html#subpath-imports, however this does not work.
// package.json
{
// ...
"imports": {
"#image": "next/image"
}
}
// page.tsx
import Image from "#image";
I originally encountered this issue while trying to get MathJax to server-render; they have imports in the above style as you can see from their package.json.
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Fri Jul 5 17:56:39 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T8122
Available memory (MB): 24576
Available CPU cores: 8
Binaries:
Node: 23.11.1
npm: 10.9.2
Yarn: 1.22.22
pnpm: 10.25.0
Relevant Packages:
next: 16.2.0 // Latest available version is detected (16.2.0).
eslint-config-next: N/A
react: 19.2.4
react-dom: 19.2.4
typescript: 5.9.3
Next.js Config:
output: N/A
Module Resolution, Turbopack
next dev (local), next build (local), next start (local), Other (Deployed), Vercel (Deployed)
No response
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!