TomBaine
TomBaine

Reputation: 773

fs.existsSync is not a function in Angular (5)

I'm trying to run an Angular 5 app through Visual Studio Code - the code compiles without errors, but I'm receiving a "fs.existsSync is not a function" error when viewing it on localhost:4200. The full error message is

module.exports< devmode.js:33 <anonymous> devmode.js:31 <anonymous> devmode.js:1 ./node_modules/selenium-webdriver/lib/devmode.js http://localhost:4200/vendor.bundle.js:1084:1
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 <anonymous> http.js:32 <anonymous> http.js:1 ./node_modules/selenium-webdriver/lib/http.js http://localhost:4200/vendor.bundle.js:1108:1
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 <anonymous> index.js:29 <anonymous> index.js:1 ./node_modules/selenium-webdriver/http/index.js http://localhost:4200/vendor.bundle.js:1044:1
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 <anonymous> login.component.ts:1 ./src/app/login/login.component.ts http://localhost:4200/main.bundle.js:284:1
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 <anonymous> app.module.ts:24 ./src/app/app.module.ts http://localhost:4200/main.bundle.js:107:1
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 <anonymous> main.ts:4 ./src/main.ts http://localhost:4200/main.bundle.js:403:1
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 [0] http://localhost:4200/main.bundle.js:411:18
__webpack_require__ http://localhost:4200/inline.bundle.js:55:12 webpackJsonpCallback http://localhost:4200/inline.bundle.js:26:23 <anonymous> http://localhost:4200/main.bundle.js:1:1

Other questions relating to this error mention Electron, but I'm not using that package.

I'm new to all of this and so don't know what other information I should be providing. If it helps, my npm version is 5.6.0, node is version 6.11.0 and the contents of my package.json are:

"dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "core-js": "^2.4.1",
    "ngx-bootstrap": "^2.0.2",
    "ngx-cookie-service": "^1.0.10",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.0",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

What do I need to be looking for in my code to fix this error?

Thanks

Upvotes: 1

Views: 2085

Answers (1)

Achraf Farouky
Achraf Farouky

Reputation: 1240

Well, it appears to have been a rogue auto-import from your editor. It was importing HttpClient from WebDriver and not Angular. Use this:

import { HttpClient } from '@angular/common/http';

Upvotes: 3

Related Questions