Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems with SSR if(!window.ace) not work #111

Open
IgorKurkov opened this issue Feb 6, 2019 · 1 comment
Open

problems with SSR if(!window.ace) not work #111

IgorKurkov opened this issue Feb 6, 2019 · 1 comment

Comments

@IgorKurkov
Copy link

Can't start SSR with Ace editor on Angular 6. I'm afraid that there I need some wrapper for SSR, but in Ace lib which used by AceEditorModule already exist some conditions for existing the window.ace or not, but it not work properly.

  • "ng2-ace-editor": "^0.3.8"
  • Angular 6.0.7

any ideas how to fix this?

npm run start:ssr

> [email protected] start:ssr I:\FRONTEND\Projects\Github\my-project - UNEXPECTED ERRORS
> node dist/server.js

I:\FRONTEND\Projects\Github\my-project - UNEXPECTED ERRORS\dist\server.js:254298
                    if (!window.ace)
                    ^

ReferenceError: window is not defined
    at I:\FRONTEND\Projects\Github\my-project - UNEXPECTED ERRORS\dist\server.js:254298:21
    at _acequire (I:\FRONTEND\Projects\Github\my-project - UNEXPECTED ERRORS\dist\server.js:235317:37)
    at Object.acequire (I:\FRONTEND\Projects\Github\my-project - UNEXPECTED ERRORS\dist\server.js:235322:26)

IIFE which produce this error and try to handle window object with ace lib inside: node_modules/ace-builds/src/ace.js

(function() {
  window.require(["ace/ace"], function(a) {
    if (a) {
      a.config.init(true);
      a.define = window.define;
    }
    if (!window.ace)
      window.ace = a;
      for (var key in a) if (a.hasOwnProperty(key))
        window.ace[key] = a[key];
        window.ace["default"] = window.ace;
        if (typeof module == "object" && typeof exports == "object" && module){
          module.exports = window.ace;
        }
     });
})();

also npm package use brace as dependency, and in it also we see this code, but its different a little bit. And I don't know how to check which of lib's code produce this error.
node_modules/brace/index.js:

(function() {
                ace.acequire(["ace/ace"], function(a) {
                    if (a) {
                        a.config.init(true);
                        a.define = ace.define;
                    }
                    if (!window.ace)
                        window.ace = a;
                    for (var key in a) if (a.hasOwnProperty(key))
                        window.ace[key] = a[key];
                });
            })();
@qubiack
Copy link

qubiack commented Mar 1, 2019

We create a fork of ng2-ace-editor where we prevent to this problem, you can use it:
https://www.npmjs.com/package/@supermemo/ng2-ace-editor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants