vue-marquee-text-component icon indicating copy to clipboard operation
vue-marquee-text-component copied to clipboard

Support SSR

Open crutchcorn opened this issue 2 years ago • 7 comments

Funnily, right after we published v2.1, I migrated my app to use Vite for SSR.

After doing so, I started getting the following errors:

ReferenceError: document is not defined
    at addStyle (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:779:22)
    at addStylesToDom (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:763:20)
    at addStylesClient (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:717:3)
    at Object.e7b3 (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:2183:14)
    at __webpack_require__ (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:21:30)
    at Object.c45f (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:1870:499)
    at __webpack_require__ (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:21:30)
    at Module.fb15 (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:2352:74)
    at __webpack_require__ (C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:21:30)
    at C:\Users\crutchcorn\git\Twitch\streampods\node_modules\vue-marquee-text-component\dist\MarqueeText.common.js:85:18

However, if I import the src file itself:

import MarqueeText from 'vue-marquee-text-component/src/components/MarqueeText.vue';

Rather than the final build, I get no such errors.

As such, this seems to me like a build setup error.

crutchcorn avatar Oct 02 '21 19:10 crutchcorn

Before I released v2.0.1 (yarn link), I included it on 2 other vue3 projects and it worked? Have you tried transpileDependencies?

EvodiaAut avatar Oct 02 '21 20:10 EvodiaAut

Were you testing with SSR apps? It worked fine for my app prior to being SSR

I'm using Vite SSR with default @vite/plugin-vue configuration

crutchcorn avatar Oct 03 '21 03:10 crutchcorn

in nuxt 3 have same issue

leosin avatar Feb 19 '22 10:02 leosin

Anyone have an idea why?

EvodiaAut avatar Feb 20 '22 08:02 EvodiaAut

@EvodiaAut @crutchcorn

<client-only>
	<marquee-text>
	Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna.
	</marquee-text>
</client-only>
components: {
	MarqueeText: () => import('vue-marquee-text-component'),
},

d4rkr3pt0r avatar Mar 19 '22 03:03 d4rkr3pt0r

@d4rkr3pt0r @crutchcorn Looks like we can close the ticket?

EvodiaAut avatar Apr 19 '22 06:04 EvodiaAut

@d4rkr3pt0r @crutchcorn Looks like we can close the ticket?

I think an ESM build would be sufficient to avoid this error. When using the Vue file itself for importing, no issue arises. See this codesandbox

Old: ~~I would suggest to change the logic so platform-specifc APIs are only access when rendering the component, not already during the import! ☺️ See my post for more info.~~

manniL avatar May 14 '22 11:05 manniL