jpuri / draftjs-utils

An collection of useful utility functions for DraftJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Importing library on server side causes crash

nealoke opened this issue · comments

When importing this library I get the error that the window is not defined as it is rendered on the server side.

In the js folder of this project the window is not used but when checking out the lib/draftjs-utils.js I see that there is a reference to the window. It would be nice if you could alter it so it doesn't crash on SSR 😢

This issue is present in any version after 0.9.4.

Yep, cause webpack build umd and using window for global object
In lib/draftjs-utils.js

!function(t,e){
  "object"==typeof exports&&"object"==typeof module
    ? module.exports=e(require("draft-js"),require("immutable"))
    : "function"==typeof define&&define.amd
      ? define(["draft-js","immutable"],e)
      :"object"==typeof exports
        ? exports.draftjsUtils=e(require("draft-js"),require("immutable"))
        : t.draftjsUtils=e(t["draft-js"],t.immutable)
}(window, function(){...})

Answer is set output.globalObject to this in webpack.prod.config.js. Documentation here. Discussion here.

Awesome. After half of year I have to check it issue again. And I wrote answer for this already

Awesome. After half of year I have to check it issue again. And I wrote answer for this already

@eseQ To be clear, that's what draftjs-utils needs to do to solve this, users of the library can't add this to their own config to eliminate this issue right?

@sedenardi correct. #39 PR was created by me one year ago )
That about build draftjs-utils package not about user webpack's configuration

Thanks for your help. Unfortunate that this library seems abandoned at this point.

Yeap =( But you can fork this library and make the changes.
I have stopped working on draftjs part for my project's

And one more moment: you can easy solve that issue on your side: just load you component with draft-editor (when using draftjs-utils only for client side (use { ssr: false } for loadable-components for example)

Yeap =( But you can fork this library and make the changes. I have stopped working on draftjs part for my project's

Out of curiosity, what library have you been using instead of draftjs?

I using draftjs - is awesome. Just don't work on it now. I mean have no time to fork and work on this library