You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
external: [
'@/lib/schemas'
],
But this is in many ways extremely awkward and, I think, undefined behavior. @/lib package names are absolutely valid locally as they are as global npm 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 with my-lib/schema export works flawlessly, so it's the @/lib pattern at fault here.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Hmm. Now that I tested it a bit again, apparently it's exactly the name @/lib that causes all of this misery. While it's valid as package name, Rollup(?) expects the organization to include at least one character after @. I previously gave up on giving org names locally since @/pkg works much better to indicate package is local and is much shorter. Also it does not conflict with anything in npm.
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: