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
Uses the "useFooContext(name)" function from the foo package, which obtains the foo context using inject.
Throws an error (Error: Not in the Foo context) if the foo context is not exist.
When bar is imported into a Vite Vue project and Wrapper and Foo are used (see App.vue for reference), the foo context not exist, resulting throw the error Error: Not in the Foo context.
Problem Analysis
Vite's Dependency Pre-Bundling will bundle bar along with foo, and you can see that Symbol("foo") is already included. However, "Wrapper.vue" is not bundled during pre-bundling but is instead imported as an external file.
packages/web/node_modules/.vite/deps/bar.js
// ...varKEY=Symbol("foo");functionuseFooContext(){returninject(KEY);}varFoo_default={setup(){constfoo=useFooContext();if(!foo)thrownewError("Not in the Foo context");return()=>h("div",`Hi ${foo}`);}};import{defaultasdefault2}from"/Users/markliang/Developer/reproduce-vite-sfc-node-modules-3rd-party-resolve-issue/node_modules/.pnpm/file+packages+bar+bar-1.0.0.tgz_vue@3.2.47/node_modules/bar/Wrapper.vue";export{Foo_defaultasFoo,default2asWrapper};// ...
When browser requesting the Wrapper.vue file from the Vite Dev Server, @vue/compiler-sfc is only called to compile it.
However, when using useFoo is directly imported from node_modules/foo, causing Symbol('foo') and the Foo component to be used differently, leading to an error thrown by Foo.
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.
aa900031
changed the title
Use Vue SFC in node_modules will be different when resolving 3rd party packages
The Vue SFC within node_modules that imports a 3rd party package may have a different path resolution than other imports.
Feb 22, 2023
aa900031
changed the title
The Vue SFC within node_modules that imports a 3rd party package may have a different path resolution than other imports.
The Vue SFC within node_modules that imports a 3rd party package may have a different path resolution than other imports
Feb 22, 2023
Describe the bug
Scenario
I have written a package called
bar
which depends on thefoo
package.bar
provides two components, "Wrapper" and "Foo", and is boundle with mkdist.foo
package, which use provide a name withSymbol('foo')
.foo
package, which obtains the foo context using inject.Error: Not in the Foo context
) if the foo context is not exist.When
bar
is imported into a Vite Vue project and Wrapper and Foo are used (see App.vue for reference), the foo context not exist, resulting throw the errorError: Not in the Foo context
.Problem Analysis
Vite's Dependency Pre-Bundling will bundle
bar
along withfoo
, and you can see thatSymbol("foo")
is already included. However, "Wrapper.vue" is not bundled during pre-bundling but is instead imported as an external file.packages/web/node_modules/.vite/deps/bar.js
When browser requesting the
Wrapper.vue
file from the Vite Dev Server,@vue/compiler-sfc
is only called to compile it.However, when using
useFoo
is directly imported fromnode_modules/foo
, causingSymbol('foo')
and theFoo
component to be used differently, leading to an error thrown byFoo
.Reproduction
https://github.com/aa900031/reproduce-vite-sfc-node-modules-3rd-party-resolve-issue
Steps to reproduce
Follow steps:
pnpm run bundle
pnpm install
pnpm dev --force
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: