Error when updating to Angular 11 from 8: Can't resolve 'util' in '/Users/foo/node_modules/request'

Viewed 1721

I'm in the process of making a huge update to my Angular 8 project → Angular 11.

I've followed the steps of https://update.angular.io/?l=3&v=8.2-11.0 pretty well.

There are a few packages in my project that don't seem to be compatible with v.^11, so I installed the packages using

npm install --legacy-peer-deps

When I try to serve the content with ng serve, I get tons of can't resolve 'util' and can't resolve 'zlib' messages. E.g.,

Error: /Users/mf/node_modules/snapdragon/lib/parser.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/snapdragon/lib'

Error: /Users/mf/node_modules/sshpk/lib/certificate.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/sshpk/lib'

Error: /Users/mf/node_modules/sshpk/lib/private-key.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/sshpk/lib'

Error: /Users/mf/node_modules/sshpk/lib/errors.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/sshpk/lib'

Error: /Users/mf/node_modules/sshpk/lib/ed-compat.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/sshpk/lib'

Error: /Users/mf/node_modules/sshpk/lib/identity.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/sshpk/lib'

Error: /Users/mf/node_modules/static-extend/index.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/static-extend'

Error: /Users/mf/node_modules/through2/through2.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/through2'

Error: /Users/mf/node_modules/tough-cookie/lib/memstore.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/tough-cookie/lib'

Error: /Users/mf/node_modules/tunnel-agent/index.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/tunnel-agent'

0mError: /Users/mf/node_modules/verror/lib/verror.js Module not found: Error: Can't resolve 'util' in '/Users/mf/node_modules/verror/lib'

Error: /Users/mf/node_modules/@google-cloud/storage/src/file.js Module not found: Error: Can't resolve 'zlib' in '/Users/mf/node_modules/@google-cloud/storage/src'

Error: /Users/mf/node_modules/request/request.js Module not found: Error: Can't resolve 'zlib' in '/Users/mf/node_modules/request'

These errors look like they span multiple packages???? I'm not sure how to resolve or whether anybody has seen this before (google suggests not exactly?).

I could not successfully set up stackBlitz as a demo for this error (I filed a ticket with them, too, about github integration).

So, best I can do to help you reproduce the issue is provide my package.json:

{
  "name": "data-jitsu",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "cypress open"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/build-angular": "~0.1102.7",
    "@angular/animations": "^11.2.8",
    "@angular/cdk": "^11.2.7",
    "@angular/common": "^11.2.8",
    "@angular/compiler": "^11.2.8",
    "@angular/compiler-cli": "^11.2.8",
    "@angular/core": "^11.2.8",
    "@angular/fire": "^6.1.4",
    "@angular/forms": "^11.2.8",
    "@angular/localize": "^11.0.0 || ^11.2.0-next",
    "@angular/material": "^11.2.7",
    "@angular/platform-browser": "^11.2.8",
    "@angular/platform-browser-dynamic": "^11.2.8",
    "@angular/router": "^11.2.8",
    "@angular/service-worker": "^11.0.0 || ^11.2.0-next",
    "@types/youtube": "^0.0.42",
    "ajv": "^8.0.5",
    "angular-froala-wysiwyg": "^3.2.6-1",
    "autoprefixer": "^10.0.2",
    "core-js": "^3.0.0",
    "d3": "^6.6.2",
    "firebase": "^8.4.0",
    "grpc": "^1.24.6",
    "hammerjs": "^2.0.8",
    "html2canvas": "^1.0.0-rc.5",
    "jquery": "^3.6.0",
    "karma": "^5.2.0 || ^6.0.0",
    "moment": "^2.29.1",
    "ng-packagr": "^11.0.0 || ^11.2.0-next",
    "ngx-youtube-player": "9.1.0",
    "postcss": "^8.0.9",
    "protractor": "^7.0.0",
    "rxjs": "^6.6.7",
    "stripe": "^8.142.0",
    "tailwindcss": "^2.0.0",
    "tslib": "^2.2.0",
    "tslint": "^6.1.0",
    "typescript": "~4.0.0 || ~4.1.0 >=4.0 <4.2",
    "util": "^0.11.1",
    "zone.js": "~0.11.3"
  },
  "devDependencies": {
    "@angular-eslint/builder": "^2.0.0",
    "@angular-eslint/eslint-plugin": "^2.0.0",
    "@angular-eslint/eslint-plugin-template": "^2.0.0",
    "@angular-eslint/schematics": "2.0.2",
    "@angular-eslint/template-parser": "^2.0.0",
    "@angular/cli": "^11.2.7",
    "@angular/compiler-cli": "^8.2.3",
    "@angular/language-service": "^11.2.8",
    "@cypress/webpack-preprocessor": "^5.7.0",
    "@types/bootstrap": "^5.0.12",
    "@types/d3": "^6.3.0",
    "@types/jasmine": "~3.6.9",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^14.14.37",
    "@typescript-eslint/eslint-plugin": "4.16.1",
    "@typescript-eslint/parser": "4.16.1",
    "chance": "^1.0.16",
    "cypress": "^7.0.0",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-cli": "~2.0.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-loader": "^8.1.0",
    "ts-node": "~9.1.1",
    "typescript": "~4.1",
    "webpack": "~4.18.1"
  }
}

And link you to the branch on my github repo: https://github.com/Atticus29/dataJitsu/tree/delete-user-version-upgrade

So,

git clone https://github.com/Atticus29/dataJitsu.git
cd dataJitsu
git checkout delete-user-version-upgrade
npm install --legacy-peer-deps
ng serve

should get you to my error.

1 Answers

May be any of the following set of commands would resolve your issue:

npm uninstall -g @angular/cli
npm install -g @angular/cli

OR

remove node_modules 
remove package-lock.json
npm install 
Related