fix: require is not defined at dist/register
when using vite
#476
Labels
bug
Something isn't working
dist/register
when using vite
#476
π The bug
With a fresh install of
Nuxt v2.15.3
+nuxt-vite v0.0.37
+@nuxtjs/composition-api v0.23.4
I got the following error:π οΈ To reproduce
I created a demo repo here. The steps to reproduce the behavior are:
yarn
ornpm i
yarn dev
ornpm run dev
onMounted
error used during thesetup()
functionrequire
error at thedist/register
file, just like the screenshotπ Expected behaviour
Expected behavior is to render the Nuxt page correctly, using the variables returned from the
setup
functionβΉοΈ Additional context
I took the liberty to dig a little bit into this issue and found that on
src/runtime/composables/index.ts
we are importing theregister
file just like theglobals
file are being imported on other places.But the weird thing is that
register
is not being recognized as a module. I patched thecomposition-api
library and did some experiments locally with the demo repo mentioned above. It turns out that by replacing theimport
statement above with a relative path:the nuxt app runs great and everything works as expected.
The PR #470 seems to modify how the
register
file is dealt with, and the motivation was the issue #468. However, looking at the issue raised on thevuejs/compostion-api
repo, it looks like in Vue3 we cannot access thevm
to get the variables fromsetup()
function, and the recommendation is to assert directly in the component. This somehow invalidates the issue #468? π€Anyway @danielroe, count on me to debug this issue =) I'll be more than happy to help and provide more insights, information and even open a PR.
The text was updated successfully, but these errors were encountered: