WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.18k forks source link

ReferenceError: window is not defined - server side rendering with node.js #25804

Closed johnstonphilip closed 7 months ago

johnstonphilip commented 4 years ago

Describe the bug When using Gutenberg Packages on the server side using node.js, when attempting to build, it throws this error:

ReferenceError: window is not defined

This appears to be due to the fact there's no window. Perhaps this should be reworked in case there is no window global set.

I am seeing this discussed here: https://dev.to/vvo/how-to-solve-window-is-not-defined-errors-in-react-and-next-js-5f97

It looks like @ellatrix already recently fixed a lot of these here: https://github.com/WordPress/gutenberg/pull/25332

I am still seeing one here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/blocks/src/api/raw-handling/ms-list-converter.js#L4

To reproduce Steps to reproduce the behavior:

  1. Install Frontity
  2. Make a new Frontity Theme and install the block-editor page
  3. Include a custom block editor in your Frontity Theme.
  4. See error upon build (npm run dev)

Expected behavior Gutenberg packages can be used on the server side with node.js without any errors.

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/blob/src/index.js#L4

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/blocks/src/api/raw-handling/image-corrector.js#L9

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/blocks/src/api/raw-handling/paste-handler.js#L41

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/viewport/src/listener.js#L37

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/components/src/scroll-lock/index.js#L18

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/dom-ready/src/index.js#L33

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/a11y/src/index.js#L18

johnstonphilip commented 4 years ago

Another here: https://github.com/WordPress/gutenberg/blob/bd79ac4f2251c38519dd13e9090b0b8ee345498b/packages/components/src/focusable-iframe/index.js#L16

alecgeatches commented 11 months ago

One more here:

https://github.com/WordPress/gutenberg/blob/658deef61912f10bc863e00b9111f41202f5c5d6/packages/blocks/src/store/process-block-type.js#L20

ellatrix commented 7 months ago

@johnstonphilip I think all or most top level ones have been fixed, so I'm going to close this issue because it's unclear what remains. If anything remains, could you open a new issue?