在 Angular 应用程序中找不到名称“Buffer”错误

问题描述 投票:0回答:1

我正在处理我的应用程序,并且开始出现此错误消息,我不知道为什么。一切都工作正常,我不确定我可以更改什么来导致这些错误发生。我尝试安装@types/node并添加

"angularCompilerOptions": {
    "types" : ["node"]
 }

到我的 tsconfig.json,但这不起作用。

ERROR in node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/types.d.ts:37:43 - error 
TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i 
@types/node` and then add `node` to the types field in your tsconfig.

37     readFileBuffer(path: AbsoluteFsPath): Buffer;
node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/types.d.ts:38:52 - error TS2591: Cannot 
find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and 
then add `node` to the types field in your tsconfig.

38     writeFile(path: AbsoluteFsPath, data: string | Buffer, exclusive?: boolean): void;                                                      
node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.d.ts:10:43 - error 
TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i 
@types/node` and then add `node` to the types field in your tsconfig.

10     readFileBuffer(path: AbsoluteFsPath): Buffer;                                             
node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.d.ts:11:52 - error 
TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i 
@types/node` and then add `node` to the types field in your tsconfig.

11     writeFile(path: AbsoluteFsPath, data: string | Buffer, exclusive?: boolean): void;

我真的被这个问题难住了。有解决这个问题的想法吗?

angular typescript npm
1个回答
0
投票

安装

@types/node
后,将
tsconfig.app.json
更新为
"types": ["node"]
下的
compilerOptions

  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": ["node"]
  },
  "files": ["src/main.ts"],
  "include": ["src/**/*.d.ts"],
  "exclude": ["src/test.ts", "src/**/*.spec.ts"]
}

© www.soinside.com 2019 - 2024. All rights reserved.