Angular 错误引用错误:";缓冲区未定义";当你在建造时`

Angular 错误引用错误:";缓冲区未定义";当你在建造时`,angular,typescript,Angular,Typescript,我试图在我的角度组件ts中使用缓冲区来编码授权字符串 它不是用ng build编译的。我尝试了npmi@types/node,并在tsconfig.json的types字段中添加了“node”。但错误仍然存在 以下是错误详细信息: 这是register.component.ts的代码 以下是我的tsconfig.json 通过此命令在计算机中安装缓冲区 npm install Buffer 然后您可以在register.component.ts中导入缓冲区,如下所示 import * as B

我试图在我的角度组件ts中使用缓冲区来编码授权字符串

它不是用
ng build
编译的。我尝试了
npmi@types/node
,并在tsconfig.json的types字段中添加了“node”。但错误仍然存在

以下是错误详细信息:

这是register.component.ts的代码

以下是我的tsconfig.json


通过此命令在计算机中安装缓冲区

npm install Buffer
然后您可以在register.component.ts中导入缓冲区,如下所示

import * as Buffer from "Buffer";

现在您可以使用Buffer了,希望不会有问题

Buffer
在前端JS中无论如何都不可用,所以您可能想看看另一种方法来做您想要的事情。另外,
Buffer.from
需要一个
整数[]
,而不是字符串
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "node"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
npm install Buffer
import * as Buffer from "Buffer";