draftjs-utils icon indicating copy to clipboard operation
draftjs-utils copied to clipboard

Importing library on server side causes crash

Open nealoke opened this issue 5 years ago • 10 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 😢

nealoke avatar Feb 03 '20 11:02 nealoke

This issue is present in any version after 0.9.4.

sedenardi avatar Jul 09 '20 19:07 sedenardi

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.

eseQ avatar Oct 13 '20 06:10 eseQ

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

eseQ avatar Jul 08 '21 09:07 eseQ

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 avatar Nov 19 '21 01:11 sedenardi

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

eseQ avatar Nov 19 '21 06:11 eseQ

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

sedenardi avatar Nov 19 '21 06:11 sedenardi

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

eseQ avatar Nov 19 '21 06:11 eseQ

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)

eseQ avatar Nov 19 '21 06:11 eseQ

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?

sedenardi avatar Nov 19 '21 07:11 sedenardi

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

eseQ avatar Nov 19 '21 07:11 eseQ