Docusaurus: [V2] | Build Fails on Server build | (undefined) API is not available in this browser.

Created on 13 Jan 2020  路  6Comments  路  Source: facebook/docusaurus

馃悰 Bug Report

Error: Sorry, the Vimeo Player API is not available in this browser.

This works well in the dev mode but the build throws an error.

Have you read the Contributing Guidelines on issues?Yes

I am trying to import and use a React component in the .mdx files in the docs folder.

abc.mdx
import Vimeo from '@u-wave/react-vimeo';
video="https://vimeo.com/1234567789"
responsive={true}
width={640}
height={480}
/>

To Reproduce

(Write your steps here:)

  1. Scaffold a v2 docusaurus project
  2. Install @u-wave/react-vimeo from npm and import it in docs/doc2.mdx file
  3. npm start -> starts the build and video is displayed in the component
  4. Try to build the project npm run build -> errors out

Expected behavior

The build version should be successful and should behave like the dev version.

(Write what you thought would happen.)

Actual Behavior

The prod build error out

(Write what happened. Add screenshots, if applicable.)
image

Reproducible Demo

https://github.com/ramakrishnan3/ducusaurus-bug-report

-> clone the repo
-> npm i
-> npm start - successful
-> npm run build - errors out
(Paste the link to an example repo, including a siteConfig.js, and exact instructions to reproduce the issue.)

bug

Most helpful comment

Probably the video component is non-compatible with server-side rendering because it uses browser-specific APIs (e.g. window), which isn't available on the server. This is not specific to Docusaurus. You could try to only render the component in a browser environment by doing

{typeof window !== 'undefined' && }

@yangshun I've been hacking away at v2 and ran into something similar, and after several days I came across this thread. This fixed the issue I had, and now I can go out for a beer :) cheers!

All 6 comments

Probably the video component is non-compatible with server-side rendering because it uses browser-specific APIs (e.g. window), which isn't available on the server. This is not specific to Docusaurus. You could try to only render the component in a browser environment by doing

{typeof window !== 'undefined' && }

@yangshun Agreed. But I am using what you have suggested already in my code https://github.com/ramakrishnan3/ducusaurus-bug-report/blob/master/docs/doc2.mdx but it does not work.

Probably the video component is non-compatible with server-side rendering because it uses browser-specific APIs (e.g. window), which isn't available on the server. This is not specific to Docusaurus. You could try to only render the component in a browser environment by doing

{typeof window !== 'undefined' && }

@yangshun I've been hacking away at v2 and ran into something similar, and after several days I came across this thread. This fixed the issue I had, and now I can go out for a beer :) cheers!

But I am using what you have suggested already in my code https://github.com/ramakrishnan3/ducusaurus-bug-report/blob/master/docs/doc2.mdx but it does not work.

That's not syntactically valid code... I meant for you to render something behind the &&.

{typeof window !== 'undefined' && <div>{...}</div>}

By the way when https://github.com/facebook/docusaurus/pull/2296 lands there will be a convenient API to check the execution environment and you no longer have to write typeof window !== 'undefined'

Closing this as it's not a Docusaurus bug.

@davodey could you please tell me how you solved the issue with Vimeo player?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rickyvetter picture rickyvetter  路  3Comments

endiliey picture endiliey  路  3Comments

philipmjohnson picture philipmjohnson  路  3Comments

NikitaIT picture NikitaIT  路  3Comments

nebrelbug picture nebrelbug  路  3Comments