下面就说说这个类库如何在Layabox2.x里面使用,以及报错 Error: Could not resolve ‘../../libs/bignumber’ from ../../../../../Users/smile/my/test/laya/demo/BNTestdemo/src/script/GameUI.ts. 后如果修改
开始编译: Wed Sep 30 2020 12:49:29 GMT+0800 (CST) -------------------------------------- [12:49:30] Working directory changed to /Applications/LayaAirIDE_2_7_0_beta.app/Contents/Resources/app [12:49:31] Using gulpfile ~/my/test/laya/demo/BNTestdemo/.laya/compile.js [12:49:31] Starting 'compile'... { Error: Could not resolve '../../libs/bignumber' from ../../../../../Users/smile/my/test/laya/demo/BNTestdemo/src/script/GameUI.ts at error (/Applications/LayaAirIDE_2_7_0_beta.app/Contents/Resources/app/node_modules/rollup/dist/rollup.js:9402:30) at ModuleLoader.handleMissingImports (/Applications/LayaAirIDE_2_7_0_beta.app/Contents/Resources/app/node_modules/rollup/dist/rollup.js:16396:17) at ModuleLoader. (/Applications/LayaAirIDE_2_7_0_beta.app/Contents/Resources/app/node_modules/rollup/dist/rollup.js:16447:26) at Generator.next () at fulfilled (/Applications/LayaAirIDE_2_7_0_beta.app/Contents/Resources/app/node_modules/rollup/dist/rollup.js:15428:28) at code: 'UNRESOLVED_IMPORT' } [12:49:34] Finished 'compile' after 2.87 s -------------------------------------- 编译结束,gulp编译耗时: 4.057s 编译结束,总耗时: 4.129s
这个 怎么回事?难道是路径错了?还是这样加载不对,经过两个小时的搜索和本地测试,发现了问题!
解决方案
原来是声明文件 需要修改才行
原来的声明长这样:代码收缩后
应该修改为 代码收缩后
主要操作
注释掉 第一行 // export default BigNumber;
把 第二行的 export 修改为 declare
删掉 export
然后去修改 GameUI.ts 因为类直接导出了,所以不需要 import BigNumber from “../../libs/bignumber”;
MiniProgramError BigNumber is not defined ReferenceError: BigNumber is not defined at GameUI.onEnable (http://127.0.0.1:42957/game/js/bundle.js:74:22) at GameUI._activeHierarchy (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:245524) at GameUI._processActive (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:245022) at GameUI._onAdded (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:246738) at GameUI._setParent (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:242101) at GameUI._setParent (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:261694) at we.addChild (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:239859) at GameUI.open (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:414537) at _onSceneLoaded (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:416882) at T.runWith (http://127.0.0.1:42957/game/libs/min/laya.core.min.js:1:15541)