swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

window is not defined error with AOT #1035

Open IonPopescu opened 7 years ago

IonPopescu commented 7 years ago

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior My goal is to set up AOT compilation in my Angular 4 application, which includes ngx-datatable. I am using the template from https://github.com/damienbod/AngularWebpackVisualStudio. "npm run webpack-production" gives me the following error:

ERROR in E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:219 return window && document && document.all && !window.atob; ^ ReferenceError: window is not defined at E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:219:9 at E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:208:46 at module.exports (E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:263:46) at Object. (E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:81:36) at __webpack_require__ (E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:20:30) at E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:63:18 at E:/MyApp/Sources/Web/node_modules/@swimlane/ngx-datatable/release/components/datatable.component.css:66:10 at ContextifyScript.Script.runInContext (vm.js:53:29) at WebpackResourceLoader._evaluate (E:\MyApp\Sources\Web\node_modules\@ngtools\webpack\src\resource_loader.js:84:34) at _compile.then (E:\MyApp\Sources\Web\node_modules\@ngtools\webpack\src\resource_loader.js:96:36)

Expected behavior No error

Reproduction of the problem Clone https://github.com/damienbod/AngularWebpackVisualStudio, add ngx-datatable to it, run "npm run webpack-production"

What is the motivation / use case for changing the behavior?

Please tell us about your environment: "dependencies": { "@angular/common": "4.4.4", "@angular/compiler": "4.4.4", "@angular/core": "4.4.4", "@angular/forms": "4.4.4", "@angular/http": "4.4.4", "@angular/platform-browser": "4.4.4", "@angular/platform-browser-dynamic": "4.4.4", "@angular/router": "4.4.4", "@swimlane/ngx-datatable": "10.2.3", "systemjs": "0.20.19", "types": "0.1.1", "zone.js": "0.8.18" }, "devDependencies": { "@ngtools/webpack": "^1.7.1", "@types/node": "^8.0.28", "@types/jasmine": "^2.6.0", "angular-router-loader": "^0.6.0", "angular2-template-loader": "^0.6.2", "awesome-typescript-loader": "^3.2.2", "clean-webpack-plugin": "^0.1.16", "codelyzer": "^3.1.2", "concurrently": "^3.5.0", "copy-webpack-plugin": "4.1.0", "css-loader": "^0.28.4", "file-loader": "1.1.5", "html-webpack-plugin": "^2.30.1", "jasmine-core": "^2.7.0", "jquery": "^3.2.1", "json-loader": "^0.5.7", "karma": "^1.7.0", "karma-chrome-launcher": "^2.2.0", "karma-jasmine": "^1.1.0", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "^0.0.31", "karma-webpack": "^2.0.4", "node-sass": "^4.5.3", "raw-loader": "^0.5.1", "rimraf": "^2.6.1", "sass-loader": "^6.0.6", "source-map-loader": "0.2.2", "style-loader": "0.19.0", "tslint": "^5.6.0", "tslint-loader": "^3.5.3", "typescript": "2.3.4", "url-loader": "0.6.2", "webpack": "^3.6.0", "webpack-dev-server": "2.9.1" },

wizarrc commented 7 years ago

@IonPopescu I can't find in the source code that refers to your error message. Where ever that code is referenced is probably where the issue is since referring to window does not work with AOT.

return window && document && document.all && !window.atob;

kcsahoo commented 7 years ago

Same error with Angular 5 and V11.0.0 while AOT compilation Excluding node_modules also does not help

izverev-aexsoft commented 6 years ago

@kcsahoo @wizarrc this error is not because of ngx-datatable Happens for me with AOT compilation, AngularWebpackVisualStudio and custom third-party angular-material theme I'm trying to integrate into it. Does not happen without AOT. Source file of the error is \node_modules\style-loader\lib\addStyles.js Seems it shouldn't be loaded with AOT, but I haven't figured yet out what causes it to be processed.

ashutoshagg commented 6 years ago

@izverev-aexsoft Did you get any solution? As i am also facing same issue "error in window is not defined" while running ng serve --aot command.

izverev-aexsoft commented 6 years ago

@ashutoshagg nopes (or maybe yes?) I had to remove AOT support. In my opinion, it is not reliable enough at this stage.

SaiKrishnaTej23 commented 6 years ago

I am facing the same issue .... I am currently using Angular 4.3.0 along with ngx-datatable 10.2.2