Module not found: Error: Can't resolve 'crypto'

前端 未结 6 1800
萌比男神i
萌比男神i 2020-12-10 01:34

I am getting the following list of errors when I run ng serve.

My package JSON is as follows:

{   \"name\": \"ProName\",   \"version\":          


        
6条回答
  •  难免孤独
    2020-12-10 01:56

    I thought I would expand on what Tarique Ahmed wrote in his answer.

    I was using an npm module that had the following line in the code:

    const crypto = require('crypto');
    

    I couldn't add:

    "browser": {
      "crypto": false
    }
    

    to the package.json because the crypto package had to be part of the build.

    It turns out that during the compilation process Angular seems to have decided to install the crypto-browserify package instead of crypto.

    Adding the following to the tsconfig.json file instructs the build to use the crypto-browserify library every time that crypto is required. As you can see, I had the same issue for the stream package.

    "paths": {
      "crypto": [
        "node_modules/crypto-browserify"
      ],
      "stream": [
        "node_modules/stream-browserify"
      ]
    }
    

提交回复
热议问题