EventSource / eventsource

EventSource client for Node.js and Browser (polyfill)
MIT License
908 stars 252 forks source link

Module not found: Error: Can't resolve 'http' in node_modules/eventsource/lib #99

Closed mattiLeBlanc closed 6 years ago

mattiLeBlanc commented 6 years ago

Hi,

I am running an Angular 5 with launch darkly feature flagging service which requires us to add the eventsource polyfill. I am trying to upgrade to Angular 6 and I am running into this error on event source:

ERROR in ./node_modules/eventsource/lib/eventsource.js
Module not found: Error: Can't resolve 'http' in '/Users/mattileblanc/www/prospa/3p-e2e-app/e2e-app/node_modules/eventsource/lib'
ERROR in ./node_modules/eventsource/lib/eventsource.js
Module not found: Error: Can't resolve 'https' in '/Users/mattileblanc/www/prospa/3p-e2e-app/e2e-app/node_modules/eventsource/lib'

I am not really sure what to do with this one, is it happening because I upgrade my typescript?

My package file

{
  "name": "app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "test-single-headless": "ng test --single-run=true --browsers=PhantomJS --reporters=progress,junit --code-coverage"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/cdk": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/flex-layout": "^6.0.0-beta.15",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "@aspnet/signalr": "^1.0.0-preview1-update1",
    "@aspnet/signalr-client": "^1.0.0-alpha2-final",
    "@markpieszak/ng-application-insights": "^5.0.0",
    "@ngrx/entity": "^5.2.0",
    "@ngrx/store": "^5.2.0",
    "angular2-uuid": "^1.1.1",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.4",
    "eventsource": "^1.0.5",
    "lodash": "^4.17.4",
    "rupture": "^0.7.1",
    "rxjs": "^6.1.0",
    "rxjs-compat": "^6.1.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.0",
    "@angular-devkit/core": "0.0.28",
    "@angular/cli": "^6.0.0",
    "@angular/compiler-cli": "^6.0.0",
    "@angular/language-service": "^6.0.0",
    "@ngrx/store-devtools": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/karma": "^1.7.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "phantomjs-prebuilt": "^2.1.16",
    "protractor": "~5.1.2",
    "reflect-metadata": "^0.1.12",
    "ts-node": "^6.0.3",
    "tslint": "~5.9.1",
    "typescript": "^2.7.2"
  }
}
mattiLeBlanc commented 6 years ago

Solved: install eventsource polyfill: https://github.com/Yaffle/EventSource

Kamforka commented 5 years ago

How did this exactly solved your issue @mattiLeBlanc?

I installed the event-source-polyfill package but still getting the http and https errors like above.

I'm using Angular 7 btw.

Any thoughts?

steve-todorov commented 5 years ago

For all the lost souls out there... Don't be discouraged! There is a fix! :rocket:

package.json
  "browser": {
    "http": false,
    "https":false,
    "net": false,
    "path": false,
    "stream": false,
    "tls": false,
    "fs": false
  },

Build:

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
ℹ 「wdm」: Compiled successfully.

https://stackoverflow.com/a/52367183/393805

mvaljento commented 6 months ago

@steve-todorov Huge thanks from the future!