ng2-ace-editor
ng2-ace-editor copied to clipboard
problems with SSR if(!window.ace) not work
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];
});
})();