블록체인
Tronweb에 NextJs15 이슈
행복한 수지아빠
2025. 7. 8. 09:51
반응형
NextJs15이상 버전 에서 tronweb을 사용시
ReferenceError: Cannot access 'TypedDataEncoder' before initialization
오류가 나온다면 다음과 같은 PR 을 참고하면 된다.
fix(#627): circular dependency issue for TypedDataEncoder by heyitsarpit · Pull Request #630 · tronprotocol/tronweb
this is fix for issue #627, which crashes builds in turbopack due a circular import for TypedDataEncoder. I ran this locally on my own codebase to confirm this does work without crashing now.
github.com
🛠️ patch-package로 PR 미적용된 tronweb 수정 적용하기
✅ 1. tronweb과 patch-package 설치
bash
복사편집
npm install tronweb npm install patch-package --save-dev
또는 yarn 사용 시:
bash
복사편집
yarn add tronweb yarn add patch-package --dev
✅ 2. package.json에 스크립트 추가
json
복사편집
"scripts": { "postinstall": "patch-package" }
이렇게 하면 npm install 혹은 yarn install 할 때마다 패치가 자동 적용됩니다.
패치 내용은 patches 폴더내 tronweb+6.0.3.patch 으로 만든 후
diff --git a/node_modules/tronweb/lib/esm/utils/typedData.js b/node_modules/tronweb/lib/esm/utils/typedData.js
index 6fad6ff..eb2fad7 100644
--- a/node_modules/tronweb/lib/esm/utils/typedData.js
+++ b/node_modules/tronweb/lib/esm/utils/typedData.js
@@ -1,10 +1,17 @@
-import { TronWeb } from '../tronweb.js';
import { keccak256, recoverAddress, concat, defineProperties, getBigInt, getBytes, hexlify, isHexString, mask, toBeHex, toQuantity, toTwos, zeroPadValue, assertArgument, id, } from 'ethers';
import { ADDRESS_PREFIX_REGEX } from './address.js';
+
+let TronWeb;
function getAddress(address) {
+ if (!TronWeb) {
+ TronWeb = require('../tronweb.js').TronWeb;
+ }
return TronWeb.address.toHex(address).replace(ADDRESS_PREFIX_REGEX, '0x');
}
function getTronAddress(address) {
+ if (!TronWeb) {
+ TronWeb = require('../tronweb.js').TronWeb;
+ }
return TronWeb.address.toHex(address);
}
const padding = new Uint8Array(32);
반응형