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
{{ message }}
Repository navigation
Getting "document is not defined" with Next.js #80
I was trying your awesome library that works seamlessly without any framework. I tried it with Next.js and no matter what I do, I am constantly getting the error as attached "document is not defined". Any idea on how to solve this issue and use it with next.js.
Thanks for the reply, document error is resolved but I couldn't figure out
the way to get data-splitting attributes working in this way. I will really
appreciate a working demo for the same.
For anyone who is still struggling to use Splitting with Next.js, I combined all the answers from previous issues and I managed to get it working in with the following code:
import"splitting/dist/splitting.css";import"splitting/dist/splitting-cells.css";constComponent=()=>{lettarget;setTimeout(()=>{if(window&&document&&target){constSplitting=require('Splitting');Splitting({by: "chars",target: target,});}});return(<><spanref={(el)=>{target=el;}}>Lorem ipsum dolor sit amet</span></>)}exportdefaultComponent;
For anyone who is still struggling to use Splitting with Next.js, I combined all the answers from previous issues and I managed to get it working in with the following code:
import"splitting/dist/splitting.css";import"splitting/dist/splitting-cells.css";constComponent=()=>{lettarget;setTimeout(()=>{if(window&&document&&target){constSplitting=require('Splitting');Splitting({by: "chars",target: target,});}});return(<><spanref={(el)=>{target=el;}}>Lorem ipsum dolor sit amet</span></>)}exportdefaultComponent;
Activity
jeff-zhenz commentedon Dec 31, 2021
see first section of this https://nextjs.org/docs/advanced-features/dynamic-import, splittingjs client-side work only
shehzadasif commentedon Dec 31, 2021
TomSmedley commentedon Jan 21, 2022
I'm having this issue with Svelte. I think since everything is moving over to Vite we really need a ESM module as well as IIFE.
d-e-v-esh commentedon Feb 2, 2022
Yes, I am having the same issue with next.js. A working solution with dynamic imports will be really appreciated.
onopko81 commentedon Mar 12, 2022
Hi, try:
const Splitting = null;
if (typeof document !==
undefined) Splitting = require('Splitting')joshtom commentedon May 17, 2022
Also having some difficulties to get it to work in NextJS.
I managed to bypass the document undefined using a dynamic import using
And this
But somehow, It's not just working. I would appreciate a solution regarding this @shshaw
draZer0 commentedon Aug 19, 2022
For anyone who is still struggling to use Splitting with Next.js, I combined all the answers from previous issues and I managed to get it working in with the following code:
joshtom commentedon Aug 19, 2022
Thank you for this @draZer0