Angular TypeError('readdirp: root argument must be a string.')

Viewed 1457

I had a perfectly good angular app working on my laptop, then I decided to move the backend out to be standalone, and since then ng serve throws the following error. It seems to get through the compile ok, and then throws an error from readdirp - anyone know whats going on?

Date: 2020-05-19T19:20:23.850Z - Hash: d2eb790e660ef9dbe323 - Time: 10777ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.
C:\__FILES\xxx\xxx\xxx\xxx\node_modules\chokidar\node_modules\readdirp\index.js:252
    throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
    ^

Google doesn't seem to know much about this. I've updated my npm packages to the latest versions on everything. Here is my package.json in case it helps:

  "dependencies": {
    "@angular/animations": "^9.1.7",
    "@angular/common": "^9.1.7",
    "@angular/compiler": "^9.1.7",
    "@angular/core": "^9.1.7",
    "@angular/elements": "^9.1.7",
    "@angular/forms": "^9.1.7",
    "@angular/platform-browser": "^9.1.7",
    "@angular/platform-browser-dynamic": "^9.1.7",
    "@angular/router": "^9.1.7",
    "@mapbox/tilebelt": "^1.0.1",
    "@types/geojson": "^7946.0.7",
    "@types/google.visualization": "0.0.52",
    "@types/mapbox-gl": "^1.10.1",
    "babel-runtime": "^6.26.0",
    "bootstrap": "^4.5.0",
    "core-js": "^3.6.5",
    "document-register-element": "^1.7.2",
    "jquery": "^3.5.1",
    "mapbox-gl": "^1.10.1",
    "nodemon": "^2.0.4",
    "popper": "^1.0.1",
    "rxjs": "^6.5.5",
    "tslib": "^2.0.0",
    "typescript": "^3.6.5",
    "zone.js": "^0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.901.6",
    "@angular/cli": "^9.1.6",
    "@angular/compiler-cli": "^9.1.7",
    "@angular/language-service": "^9.1.7",
    "@types/jasmine": "^3.5.10",
    "@types/jasminewd2": "~2.0.8",
    "@types/node": "^14.0.3",
    "codelyzer": "^5.2.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "^5.0.2",
    "karma": "^5.0.8",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "^3.0.2",
    "karma-jasmine": "^3.1.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "protractor": "^7.0.0",
    "ts-node": "^8.10.1",
    "tslint": "^6.1.2"
  }

Edit: If I build it and serve it, no problems, and seems to get through the dev compile ok. So something to do with serving the develepment app?

1 Answers

@Radik had the right approach. I deleted node_modules, package.json and package-lock.json, took an old package.json from before I deleted the backend and did an npm install. Instead of deleting the lines I didn't need from the package.json as I did last time, this time I did npm uninstall on each package and ran ng serve after each to make sure it still worked. Then I ran npm outdated and updated each package using npm install xxx@latest. Finally I did npm prune. I can't say which step fixed the problem, but its working fine now.

Related