Anime: ReferenceError: document is not defined

Created on 10 Jan 2019  路  7Comments  路  Source: juliangarnier/anime

3.0.0 no longer works in Next JS [v7.0.2].

ReferenceError: document is not defined at Object.<anonymous> (/node_modules/animejs/lib/anime.js:919:1)

Previously this was a non-issue, I'm left trying to figure out a way to dynamically import this without ssr. Looking forward to using these new features!

Most helpful comment

Released in 3.0.1 !

All 7 comments

I found a work-around that would work in React for now. I can require animejs after the component mounts:

```javascript
componentDidMount = () => {
const anime = require("animejs/lib/anime.js");
}

I ran into the same problem as I'm using anime inside of React components that run both in the client and on the server. The problem can be tracked down to this line. Here anime is using document which creates a problem when this file is required or imported inside Node.js since document is not available in Node.

I've created a fork, added and if-statement as a guard and tested it using Next.js.

@juliangarnier I could prepare a PR if this helps?

Same problem in vuepress T_T!

@mattwagl yes please, PR to the dev branch.
Thanks!

Awesome! When I鈥榤 back at my computer I鈥榣l send a PR to dev 馃槉. One last question: in order to test it from an application I had to create a build and commit it. Is this a problem? Should I create a clean branch without the build first? Thanks for the help.

I've removed the build and prepared a PR with just the bugfix. Any chance this can make it into a patch release?

Released in 3.0.1 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ndimatteo picture ndimatteo  路  5Comments

littlee picture littlee  路  3Comments

edenprojectde picture edenprojectde  路  5Comments

Elaborate3P1C picture Elaborate3P1C  路  7Comments

DavudSafarli picture DavudSafarli  路  5Comments