Angular 7 で開発を進めていると、以下のエラーが発生してコンパイルができなくなりました。
error TS2580: 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.
よくあるエラーで、@types/node
がインストールされていないことが原因だと思いましたが、Angular 7 では、src/tsconfig.app.json
にも設定が必要だったので、メモしておきます。
1. @types/node をインストール
以下のコマンドで、@types/node
をインストールします。
npm install --save @types/node
2. tsconfig.json に以下を記述
tsconfig.json
ファイルに以下を記述します。
"compilerOptions": {
"types": ["node"]
}
3. src/tsconfig.app.json にも、同じく記述
src/tsconfig.app.json
にも同じ記述が必要です。
"compilerOptions": {
"types": ["node"]
}
4. 参考URL
https://stackoverflow.com/questions/53115665/cannot-find-name-require-in-angular-7typescript-3-1-3
コメント