Package exports eg @/pkg/foo
not resolved locally
#19292
Labels
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
So I have a local package
@/lib
in pnpm monorepo which works and I'm able to use it correctly. However, the second I add another"exports"
definition to its package.json, Vite (or more specifically it seems Rollup) fails to import it.error during build:
[vite]: Rollup failed to resolve import "@/lib/schemas" from "/Users/teemu/git_projects/omat/vite-module-not-found-bug/packages/bug/src/index.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
Using just
@/lib
works fine. It's the subpathing@/lib/schemas
that makes Rollup/Vite go haywire. If I externalize it, as the log suggests it, this doesn't work:Because, as you should realize, the
@/lib
value does not externalize@/lib/schemas
. So what you should do is:But this is in many ways extremely awkward and, I think, undefined behavior.
@/lib
package names are absolutely valid locally as they are as globalnpm
packages. And"exports"
should work as intended no matter what the package name is, as long as it valid. The fact that this specific pattern blows up the build with a vague error that gives no clue what's going on is terrible.I might have encountered this bug before but probably thought it was going to be fixed one day.
Using
my-lib
as the package name withmy-lib/schema
export works flawlessly, so it's the@/lib
pattern at fault here.Reproduction
https://github.com/TeemuKoivisto/vite-module-not-found-bug
Steps to reproduce
git clone https://github.com/TeemuKoivisto/vite-module-not-found-bug
pnpm i
pnpm pnpm --filter lib --filter my-lib build
pnpm --filter bug build
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: