본문 바로가기
Framework/React

[React] Uncaught ReferenceError: Buffer is not defined in React

by pcm9881 2023. 8. 1.

 

리액트 17 버전에서 18 버전으로 변경하면서 아래와 같은 오류가 나와서 해결한 내용을 정리합니다.

Uncaught ReferenceError: Buffer is not defined in React

 

해결방안

 

buffer 설치

 

npm

npm install --save buffer

 

yarn

yarn add buffer --save

 

App.js 추가

 

import React from "react";
...
import { Buffer } from "buffer";

Buffer.from("anything", "base64");
window.Buffer = window.Buffer || require("buffer").Buffer;

const App = () => {
    ...
};

export default App;

 

이렇게 해결했습니다.

 

References

https://stackoverflow.com/questions/67804053/uncaught-referenceerror-buffer-is-not-defined-in-react

 

Uncaught ReferenceError: Buffer is not defined in React

If I add the following lines into my code it throws the following error: import { BIP32Interface } from "bip32"; let node: BIP32Interface = bip32.fromBase58(key); Error: Uncaught

stackoverflow.com

 

728x90

댓글