web-dev-qa-db-fra.com

Angular 6 Plusieurs Impossible de résoudre les erreurs (crypto, fs, http, https, net, chemin, flux, tls, zlib)

Je construis une application Angular 6, mais chaque fois que je veux servir à localhost, j'obtiens ces erreurs: 

ERROR in ./node_modules/aws-sign2/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\aws-sign2'
ERROR in ./node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\aws4'
ERROR in ./node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\ecc-jsbn'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\http-signature\lib'
ERROR in ./node_modules/http-signature/lib/verify.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\http-signature\lib'
ERROR in ./node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\oauth-sign'
ERROR in ./node_modules/request/lib/oauth.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request\lib'
ERROR in ./node_modules/request/lib/helpers.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request\lib'
ERROR in ./node_modules/request/lib/hawk.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request\lib'
ERROR in ./node_modules/sshpk/lib/signature.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/private-key.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/certificate.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/fingerprint.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/key.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/dhe.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/identity.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/utils.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/sshpk/lib/formats/pem.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib\formats'
ERROR in ./node_modules/sshpk/lib/formats/ssh-private.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib\formats'
ERROR in ./node_modules/sshpk/lib/formats/openssh-cert.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib\formats'
ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request\lib'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\sorou\projects\tunrWeb\node_modules\forever-agent'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\sorou\projects\tunrWeb\node_modules\http-signature\lib'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\sorou\projects\tunrWeb\node_modules\tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'https' in 'C:\Users\sorou\projects\tunrWeb\node_modules\forever-agent'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'https' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'https' in 'C:\Users\sorou\projects\tunrWeb\node_modules\tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\sorou\projects\tunrWeb\node_modules\forever-agent'
ERROR in ./node_modules/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\sorou\projects\tunrWeb\node_modules\tough-cookie\lib'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\sorou\projects\tunrWeb\node_modules\tunnel-agent'
ERROR in ./node_modules/mime-types/index.js
Module not found: Error: Can't resolve 'path' in 'C:\Users\sorou\projects\tunrWeb\node_modules\mime-types'
ERROR in ./node_modules/assert-plus/assert.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\sorou\projects\tunrWeb\node_modules\assert-plus'
ERROR in ./node_modules/combined-stream/lib/combined_stream.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\sorou\projects\tunrWeb\node_modules\combined-stream\lib'
ERROR in ./node_modules/delayed-stream/lib/delayed_stream.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\sorou\projects\tunrWeb\node_modules\delayed-stream\lib'
ERROR in ./node_modules/isstream/isstream.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\sorou\projects\tunrWeb\node_modules\isstream'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request'
ERROR in ./node_modules/sshpk/lib/ed-compat.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\sorou\projects\tunrWeb\node_modules\sshpk\lib'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\sorou\projects\tunrWeb\node_modules\forever-agent'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\sorou\projects\tunrWeb\node_modules\tunnel-agent'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\sorou\projects\tunrWeb\node_modules\request'

Ceci est mon package.json:

{
  "name": "tunr-web",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.7",
    "@angular/cdk": "github:angular/cdk-builds",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/material": "github:angular/material2-builds",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "angular-svg-round-progressbar": "^2.0.0",
    "angularfire2": "^5.0.0-rc.11",
    "core-js": "^2.5.4",
    "firebase": "^5.1.0",
    "hammerjs": "^2.0.8",
    "jquery": "^3.3.1",
    "ng-scrollreveal": "^2.2.0",
    "ng2-scroll-to-el": "^1.2.1",
    "ngx-facebook": "^2.4.0",
    "ngx-infinite-scroll": "^6.0.1",
    "ngx-sharebuttons": "^4.1.4",
    "rxjs": "^6.2.1",
    "rxjs-compat": "^6.2.1",
    "time-ago-pipe": "^1.3.2",
    "youtube-search": "^1.1.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "~6.0.8",
    "@angular/compiler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "@types/scrollreveal": "0.0.3",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "TypeScript": "~2.7.2"
  }
}

Est-ce que quelqu'un sait ce qui ne va pas? Aucun des modules mentionnés ci-dessus n'existe dans mon fichier node_modules (je peux en installer certains, mais 'crypto', par exemple, est intégré). Comment puis-je obtenir ces dossiers? Cela me rend fou. 

16
Zizazorro

Cela est dû aux dépendances qui importent des modules de noeud qui ne sont pas disponibles dans le navigateur. Ajoutez à votre package.json les modules qui génèrent des erreurs:

"browser": {
    "http": false,
    "https":false,
    "net": false,
    "path": false,
    "stream": false,
    "tls": false
}
8
snorberhuis

Vous utilisez la dernière version de Angular CLI. Certains paquets npm ne sont plus pris en charge. C'est maintenant un module de nœud intégré. Si vous avez utilisé la crypto, vous devriez passer à celle qui est intégrée.

Pour résoudre votre problème avec crypto, libs de flux, , Allez à,

node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js

déposer et faire le changement suivant,

`node: {crypto: true, stream: true}`
5
Azkar Moulana

Vous devez trouver les packages de nœud ajoutés en tant que dépendances qui sont à l'origine de ce problème. Ouvrez package-lock.json. La recherche de crypto peut trouver la chaîne de dépendances menant au nom du paquet inclus dans la section des dépendances de package.json. Dans mon cas, la plupart de ces bibliothèques ont été importées avec le paquet npm 'request'.

1
Sanju Varghese

La version actuelle de Angular-cli n'installe pas certains paquets comme zlib, contrairement aux versions précédentes. Vous devrez peut-être installer certains packages manuellement pour résoudre ces erreurs.

0
Harini P

Utilisez le paquet ngx-build-plus - https://github.com/manfredsteyer/ngx-build-plus - et fournissez la configuration supplémentaire. De cette façon, vous n'avez pas à mettre à jour manuellement les fichiers de modules de nœud à chaque fois que vous effectuez une installation.

0
Jebe