Angular 6:编译失败:无法在 ./node_modules/hash-base 中解析 'stream'

Angular 6: Failed to compile: Can't resolve 'stream' in ./node_modules/hash-base

我更新了三个 Angular 5 个应用程序到 Angular 6 个,但最后一个给我带来了麻烦。 每次我尝试编译 (serve/build、jit/aot、dev/prod) 时,我都会收到此错误:

ERROR in ./node_modules/hash-base/index.js
Module not found: Error: Can't resolve 'stream' in '[...]/node_modules/hash-base'
ℹ 「wdm」: Failed to compile.

hash-base 似乎是一个 webpack 依赖项:

@eagle5/editor-app@0.2.6
└─┬ @angular-devkit/build-angular@0.6.1
  └─┬ webpack@4.6.0
    └─┬ node-libs-browser@2.1.0
      └─┬ crypto-browserify@3.12.0
        └─┬ create-hash@1.2.0
          ├─┬ md5.js@1.3.4
          │ └── hash-base@3.0.4 
          └─┬ ripemd160@2.0.2
            └── hash-base@3.0.4  deduped

这个应用程序的一些特点是我在应用程序文件夹旁边的 ./src 中有一个框架,我安装了一个 git 存储库作为 npm 包,并在我的 [=30= 中导入了一些打字稿定义]:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "paths": {
      "@nettrek/*": [
        "./@nettrek/*"
      ]
    }
  },
  "include": [
    "./src/**/*",
    "./node_modules/@eagle5/player-core/dto/**/*"
  ],
  "angularCompilerOptions": {
    "preserveWhitespaces": false
  }
}

我尝试安装 this stream npm 包,但此版本没有 hash-base 使用的 stream.Transform 扩展。

我试过节点 8.11.1 和 10.1.0

好的,我找到了错误的原因。我们自己在一个 class 中使用了 md5.js,但忘记将其放入我们的 package.json 中,因为它已经安装好了。 Md5.js 当然需要 angular 6 不再支持的浏览器填充节点。

尝试将 'stream' 添加到您的项目中

npm install stream --save