angular / universal

Server-side rendering and Prerendering for Angular
MIT License
4.04k stars 484 forks source link

ReferenceError: window is not defined for hammer.js when npm run serve:ssr #2007

Closed cwooi95 closed 3 years ago

cwooi95 commented 3 years ago
# 🐞 Bug report #### What modules are related to this issue?

Is this a regression?

No

Description

When running npm run serve:ssr after installing @nguniversal, there is conflict with hammer.js module, error shows window is not defined.

🔬 Minimal Reproduction

1) ng add @nguniversal/express-engine --clientProject roomer-app 2) npm run build:ssr (success) 3) npm run serve:ssr (failed)

🔥 Exception or Error


> roomer-app@0.0.0 serve:ssr /Users/ooicw/Documents/roomer-app
> node dist/server

/Users/ooicw/Documents/roomer-app/dist/server.js:427857
})(window, document, 'Hammer');
   ^

ReferenceError: window is not defined
    at Object../node_modules/hammerjs/hammer.js (/Users/ooicw/Documents/roomer-app/dist/server.js:427857:4)
    at __webpack_require__ (/Users/ooicw/Documents/roomer-app/dist/server.js:147189:30)
    at Object../src/app/app.module.ts (/Users/ooicw/Documents/roomer-app/dist/server.js:547020:37)
    at __webpack_require__ (/Users/ooicw/Documents/roomer-app/dist/server.js:147189:30)
    at Object../src/app/app.server.module.ngfactory.js (/Users/ooicw/Documents/roomer-app/dist/server.js:547066:34)
    at __webpack_require__ (/Users/ooicw/Documents/roomer-app/dist/server.js:147189:30)
    at Object../src/main.server.ts (/Users/ooicw/Documents/roomer-app/dist/server.js:561771:37)
    at __webpack_require__ (/Users/ooicw/Documents/roomer-app/dist/server.js:147189:30)
    at Object.0 (/Users/ooicw/Documents/roomer-app/dist/server.js:561795:18)
    at __webpack_require__ (/Users/ooicw/Documents/roomer-app/dist/server.js:147189:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! roomer-app@0.0.0 serve:ssr: `node dist/server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the roomer-app@0.0.0 serve:ssr script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ooicw/.npm/_logs/2021-03-03T21_49_02_342Z-debug.log

Error.log

🌍 Your Environment

Angular CLI: 9.1.3 Node: 12.18.3 OS: darwin x64

Angular: 9.1.3

Other information

package.json

{
  "name": "roomer-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:prod": "ng build --prod --aot --vendor-chunk --common-chunk --delete-output-path --buildOptimizer",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve:ssr": "node dist/server",
    "build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
    "build:client-and-server-bundles": "ng build --prod && ng run roomer-app:server:production",
    "bundle-report": "ng build --stats-json && webpack-bundle-analyzer ./dist/browser/stats-es2015.json"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.1.0",
    "@angular-material-extensions/select-country": "1.1.0",
    "@angular/animations": "^9.1.9",
    "@angular/cdk": "^9.2.4",
    "@angular/common": "^9.1.3",
    "@angular/compiler": "^9.1.3",
    "@angular/core": "^9.1.3",
    "@angular/fire": "^6.0.0",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "^9.1.9",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "^9.1.3",
    "@angular/platform-browser-dynamic": "^9.1.3",
    "@angular/platform-server": "^9.1.3",
    "@angular/router": "^9.1.3",
    "@angular/service-worker": "^9.1.3",
    "@kolkov/ngx-gallery": "^1.2.0",
    "@material/elevation": "^5.1.0",
    "@ng-toolkit/universal": "^8.0.3",
    "@nguniversal/express-engine": "^7.0.2",
    "@nguniversal/module-map-ngfactory-loader": "v7.0.2",
    "@tensorflow/tfjs": "^2.0.1",
    "@typeform/embed": "^0.22.0",
    "@types/googlemaps": "^3.39.11",
    "angularfire2": "^5.4.2",
    "angularx-social-login": "^2.3.1",
    "chart.js": "^2.9.3",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "firebase": "^7.14.3",
    "firebase-admin": "^8.12.1",
    "firebase-functions": "^3.6.2",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "ng-gallery": "^5.0.0-beta.2",
    "ng2-charts": "^2.3.0",
    "ng5-slider": "^1.2.4",
    "ngx-doughnut-chart": "0.0.4",
    "ngx-lightbox": "^2.1.2",
    "ngx-pagination": "^5.0.0",
    "ngx-paginator": "0.0.14",
    "ngx-stripe": "^9.0.2",
    "npm-update": "^2.1.0",
    "npm-upgrade": "^2.0.3",
    "package.json": "^2.0.1",
    "protractor": "^7.0.0",
    "rxjs": "^6.5.5",
    "svg-country-flags": "^1.2.7",
    "tslib": "^1.11.1",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.900",
    "@angular-devkit/build-angular": "^0.901.12",
    "@angular/cli": "^9.1.3",
    "@angular/compiler-cli": "^9.1.3",
    "@angular/language-service": "^9.1.3",
    "@types/hammerjs": "^2.0.36",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.12.44",
    "@types/stripe-checkout": "^1.0.3",
    "@types/stripe-v3": "^3.1.17",
    "codelyzer": "^5.2.2",
    "compression-webpack-plugin": "^6.0.4",
    "firebase-tools": "^8.0.0",
    "fuzzy": "^0.1.3",
    "inquirer": "^6.2.2",
    "inquirer-autocomplete-prompt": "^1.0.1",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^5.0.9",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.3",
    "license-webpack-plugin": "^2.3.0",
    "ts-loader": "^5.2.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "^3.7.5",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.1.0"
  }
}
CaerusKaru commented 3 years ago

Please read the issue template.

angular-automatic-lock-bot[bot] commented 3 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.